Algorithms
Hard
2940
3181
Find Building Where Alice and Bob Can Meet
find-building-where-alice-and-bob-can-meet
"""
You are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the ith building.
If a person is in building i, they can move to any other building j if and only if i < j and heights[i] < heights[j].
You are also given another array queries where queries[i] = [ai, bi]. On the ith query, Alice is in building ai while Bob is in building bi.
Return an array ans where ans[i] is the index of the leftmost building where Alice and Bob can meet on the ith query. If Alice and Bob cannot move to a common building on query i, set ans[i] to -1.

Example 1:

Input: heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]]
Output: [2,5,-1,5,2]
Explanation: In the first query, Alice and Bob can move to building 2 since heights[0] < heights[2] and heights[1] < heights[2]. 
In the second query, Alice and Bob can move to building 5 since heights[0] < heights[5] and heights[3] < heights[5]. 
In the third query, Alice cannot meet Bob since Alice cannot move to any other building.
In the fourth query, Alice and Bob can move to building 5 since heights[3] < heights[5] and heights[4] < heights[5].
In the fifth query, Alice and Bob are already in the same building.  
For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.
For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.

Example 2:

Input: heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]]
Output: [7,6,-1,4,6]
Explanation: In the first query, Alice can directly move to Bob's building since heights[0] < heights[7].
In the second query, Alice and Bob can move to building 6 since heights[3] < heights[6] and heights[5] < heights[6].
In the third query, Alice cannot meet Bob since Bob cannot move to any other building.
In the fourth query, Alice and Bob can move to building 4 since heights[3] < heights[4] and heights[0] < heights[4].
In the fifth query, Alice can directly move to Bob's building since heights[1] < heights[6].
For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.
For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.



Constraints:

1 <= heights.length <= 5 * 104
1 <= heights[i] <= 109
1 <= queries.length <= 5 * 104
queries[i] = [ai, bi]
0 <= ai, bi <= heights.length - 1
"""
class Solution:
    def leftmostBuildingQueries(self, heights: List[int], queries: List[List[int]]) -> List[int]:
        
You are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the ith building.
If a person is in building i, they can move to any other building j if and only if i < j and heights[i] < heights[j].
You are also given another array queries where queries[i] = [ai, bi]. On the ith query, Alice is in building ai while Bob is in building bi.
Return an array ans where ans[i] is the index of the leftmost building where Alice and Bob can meet on the ith query. If Alice and Bob cannot move to a common building on query i, set ans[i] to -1.

Example 1:

Input: heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]]
Output: [2,5,-1,5,2]
Explanation: In the first query, Alice and Bob can move to building 2 since heights[0] < heights[2] and heights[1] < heights[2]. 
In the second query, Alice and Bob can move to building 5 since heights[0] < heights[5] and heights[3] < heights[5]. 
In the third query, Alice cannot meet Bob since Alice cannot move to any other building.
In the fourth query, Alice and Bob can move to building 5 since heights[3] < heights[5] and heights[4] < heights[5].
In the fifth query, Alice and Bob are already in the same building.  
For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.
For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.

Example 2:

Input: heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]]
Output: [7,6,-1,4,6]
Explanation: In the first query, Alice can directly move to Bob's building since heights[0] < heights[7].
In the second query, Alice and Bob can move to building 6 since heights[3] < heights[6] and heights[5] < heights[6].
In the third query, Alice cannot meet Bob since Bob cannot move to any other building.
In the fourth query, Alice and Bob can move to building 4 since heights[3] < heights[4] and heights[0] < heights[4].
In the fifth query, Alice can directly move to Bob's building since heights[1] < heights[6].
For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.
For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.



Constraints:

1 <= heights.length <= 5 * 104
1 <= heights[i] <= 109
1 <= queries.length <= 5 * 104
queries[i] = [ai, bi]
0 <= ai, bi <= heights.length - 1


Please complete the code below to solve above prblem:
```python
class Solution:
    def leftmostBuildingQueries(self, heights: List[int], queries: List[List[int]]) -> List[int]:
        
```

my_solution = Solution()

test_input = { "heights": [6,4,8,5,2,7], "queries": [[0,1],[0,3],[2,4],[3,4],[2,2]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [2,5,-1,5,2]

test_input = { "heights": [5,3,8,2,6,1,4,6], "queries": [[0,7],[3,5],[5,2],[3,0],[1,6]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [7,6,-1,4,6]

test_input = { "heights": [1], "queries": [[0,0]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0]

test_input = { "heights": [1000000000], "queries": [[0,0]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0]

test_input = { "heights": [1,2], "queries": [[0,0],[0,1],[1,0],[1,1]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,1,1]

test_input = { "heights": [2,1], "queries": [[0,0],[0,1],[1,0],[1,1]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,1]

test_input = { "heights": [1,2,3], "queries": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,1,1,2,2,2,2]

test_input = { "heights": [1,3,2], "queries": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,1,1,-1,2,-1,2]

test_input = { "heights": [2,1,3], "queries": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,2,1,2,2,2,2]

test_input = { "heights": [2,3,1], "queries": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,-1,1,1,-1,-1,-1,2]

test_input = { "heights": [3,1,2], "queries": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,1,2,-1,2,2]

test_input = { "heights": [3,2,1], "queries": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,1,-1,-1,-1,2]

test_input = { "heights": [1,2,3,4], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,2,3,2,2,2,3,3,3,3,3]

test_input = { "heights": [1,2,4,3], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,2,3,2,2,2,-1,3,3,-1,3]

test_input = { "heights": [1,3,2,4], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,3,3,2,3,2,3,3,3,3,3]

test_input = { "heights": [1,3,4,2], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,2,-1,2,2,2,-1,3,-1,-1,3]

test_input = { "heights": [1,4,2,3], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,-1,-1,2,-1,2,3,3,-1,3,3]

test_input = { "heights": [1,4,3,2], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,-1,-1,2,-1,2,-1,3,-1,-1,3]

test_input = { "heights": [2,1,3,4], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,2,1,2,3,2,2,2,3,3,3,3,3]

test_input = { "heights": [2,1,4,3], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,2,1,2,3,2,2,2,-1,3,3,-1,3]

test_input = { "heights": [2,3,1,4], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,1,1,3,3,3,3,2,3,3,3,3,3]

test_input = { "heights": [2,3,4,1], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,-1,1,1,2,-1,2,2,2,-1,-1,-1,-1,3]

test_input = { "heights": [2,4,1,3], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,1,1,-1,-1,3,-1,2,3,3,-1,3,3]

test_input = { "heights": [2,4,3,1], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,-1,1,1,-1,-1,2,-1,2,-1,-1,-1,-1,3]

test_input = { "heights": [3,1,2,4], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,3,1,2,3,3,2,2,3,3,3,3,3]

test_input = { "heights": [3,1,4,2], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,-1,2,1,2,3,2,2,2,-1,-1,3,-1,3]

test_input = { "heights": [3,2,1,4], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,3,1,3,3,3,3,2,3,3,3,3,3]

test_input = { "heights": [3,2,4,1], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,-1,2,1,2,-1,2,2,2,-1,-1,-1,-1,3]

test_input = { "heights": [3,4,1,2], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,-1,-1,1,1,-1,-1,-1,-1,2,3,-1,-1,3,3]

test_input = { "heights": [3,4,2,1], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,-1,-1,1,1,-1,-1,-1,-1,2,-1,-1,-1,-1,3]

test_input = { "heights": [4,1,2,3], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,2,3,-1,2,2,3,-1,3,3,3]

test_input = { "heights": [4,1,3,2], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,2,3,-1,2,2,-1,-1,3,-1,3]

test_input = { "heights": [4,2,1,3], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,3,3,-1,3,2,3,-1,3,3,3]

test_input = { "heights": [4,2,3,1], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,2,-1,-1,2,2,-1,-1,-1,-1,3]

test_input = { "heights": [4,3,1,2], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,-1,-1,-1,-1,2,3,-1,-1,3,3]

test_input = { "heights": [4,3,2,1], "queries": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,-1,-1,-1,-1,2,-1,-1,-1,-1,3]

test_input = { "heights": [1,2,3,4,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,3,4,3,3,3,3,4,4,4,4,4,4]

test_input = { "heights": [1,2,3,5,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,3,4,3,3,3,3,-1,4,4,4,-1,4]

test_input = { "heights": [1,2,4,3,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,4,4,3,3,4,3,4,4,4,4,4,4]

test_input = { "heights": [1,2,4,5,3], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,3,-1,3,3,3,3,-1,4,4,-1,-1,4]

test_input = { "heights": [1,2,5,3,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,4,4,4,-1,4,4]

test_input = { "heights": [1,2,5,4,3], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,-1,4,4,-1,-1,4]

test_input = { "heights": [1,3,2,4,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,3,3,4,2,3,2,3,4,3,3,3,3,4,4,4,4,4,4]

test_input = { "heights": [1,3,2,5,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,3,3,4,2,3,2,3,4,3,3,3,3,-1,4,4,4,-1,4]

test_input = { "heights": [1,3,4,2,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,4,4,2,2,2,4,4,3,4,4,3,4,4,4,4,4,4]

test_input = { "heights": [1,3,4,5,2], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,-1,2,2,2,3,-1,3,3,3,3,-1,4,-1,-1,-1,4]

test_input = { "heights": [1,3,5,2,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,4,4,2,2,2,-1,-1,3,4,-1,3,4,4,4,-1,4,4]

test_input = { "heights": [1,3,5,4,2], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,-1,2,2,2,-1,-1,3,3,-1,3,-1,4,-1,-1,-1,4]

test_input = { "heights": [1,4,2,3,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,4,4,4,2,4,2,3,4,3,4,3,3,4,4,4,4,4,4]

test_input = { "heights": [1,4,2,5,3], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,3,3,-1,2,3,2,3,4,3,3,3,3,-1,4,-1,4,-1,4]

test_input = { "heights": [1,4,3,2,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,4,4,4,2,4,2,4,4,3,4,4,3,4,4,4,4,4,4]

test_input = { "heights": [1,4,3,5,2], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,3,3,-1,2,3,2,3,-1,3,3,3,3,-1,4,-1,-1,-1,4]

test_input = { "heights": [1,4,5,2,3], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,-1,-1,2,2,2,-1,-1,3,-1,-1,3,4,4,-1,-1,4,4]

test_input = { "heights": [1,4,5,3,2], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,-1,-1,2,2,2,-1,-1,3,-1,-1,3,-1,4,-1,-1,-1,4]

test_input = { "heights": [1,5,2,3,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,3,4,3,-1,3,3,4,4,-1,4,4,4]

test_input = { "heights": [1,5,2,4,3], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,3,4,3,-1,3,3,-1,4,-1,4,-1,4]

test_input = { "heights": [1,5,3,2,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,4,4,3,-1,4,3,4,4,-1,4,4,4]

test_input = { "heights": [1,5,3,4,2], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,3,-1,3,-1,3,3,-1,4,-1,-1,-1,4]

test_input = { "heights": [1,5,4,2,3], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,-1,-1,3,-1,-1,3,4,4,-1,-1,4,4]

test_input = { "heights": [1,5,4,3,2], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,-1,-1,3,-1,-1,3,-1,4,-1,-1,-1,4]

test_input = { "heights": [2,1,3,4,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,3,4,3,3,3,3,4,4,4,4,4,4]

test_input = { "heights": [2,1,3,5,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,3,4,3,3,3,3,-1,4,4,4,-1,4]

test_input = { "heights": [2,1,4,3,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,4,4,3,3,4,3,4,4,4,4,4,4]

test_input = { "heights": [2,1,4,5,3], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,3,-1,3,3,3,3,-1,4,4,-1,-1,4]

test_input = { "heights": [2,1,5,3,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,4,4,4,-1,4,4]

test_input = { "heights": [2,1,5,4,3], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,-1,4,4,-1,-1,4]

test_input = { "heights": [2,3,1,4,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,3,3,4,3,3,2,3,4,3,3,3,3,4,4,4,4,4,4]

test_input = { "heights": [2,3,1,5,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,3,3,4,3,3,2,3,4,3,3,3,3,-1,4,4,4,-1,4]

test_input = { "heights": [2,3,4,1,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,2,4,4,2,2,2,4,4,4,4,4,3,4,4,4,4,4,4]

test_input = { "heights": [2,3,4,5,1], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,2,3,-1,2,2,2,3,-1,3,3,3,3,-1,-1,-1,-1,-1,4]

test_input = { "heights": [2,3,5,1,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,2,4,4,2,2,2,-1,-1,4,4,-1,3,4,4,4,-1,4,4]

test_input = { "heights": [2,3,5,4,1], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,2,3,-1,2,2,2,-1,-1,3,3,-1,3,-1,-1,-1,-1,-1,4]

test_input = { "heights": [2,4,1,3,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,4,4,4,3,4,2,3,4,3,4,3,3,4,4,4,4,4,4]

test_input = { "heights": [2,4,1,5,3], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,3,3,-1,3,3,2,3,4,3,3,3,3,-1,4,-1,4,-1,4]

test_input = { "heights": [2,4,3,1,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,4,4,4,2,4,2,4,4,4,4,4,3,4,4,4,4,4,4]

test_input = { "heights": [2,4,3,5,1], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,3,3,-1,2,3,2,3,-1,3,3,3,3,-1,-1,-1,-1,-1,4]

test_input = { "heights": [2,4,5,1,3], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,2,-1,-1,2,2,2,-1,-1,4,-1,-1,3,4,4,-1,-1,4,4]

test_input = { "heights": [2,4,5,3,1], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,2,-1,-1,2,2,2,-1,-1,3,-1,-1,3,-1,-1,-1,-1,-1,4]

test_input = { "heights": [2,5,1,3,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,-1,-1,-1,3,-1,2,3,4,3,-1,3,3,4,4,-1,4,4,4]

test_input = { "heights": [2,5,1,4,3], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,-1,-1,-1,3,-1,2,3,4,3,-1,3,3,-1,4,-1,4,-1,4]

test_input = { "heights": [2,5,3,1,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,-1,-1,-1,2,-1,2,4,4,4,-1,4,3,4,4,-1,4,4,4]

test_input = { "heights": [2,5,3,4,1], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,-1,-1,-1,2,-1,2,3,-1,3,-1,3,3,-1,-1,-1,-1,-1,4]

test_input = { "heights": [2,5,4,1,3], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,-1,-1,-1,2,-1,2,-1,-1,4,-1,-1,3,4,4,-1,-1,4,4]

test_input = { "heights": [2,5,4,3,1], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,-1,-1,-1,2,-1,2,-1,-1,3,-1,-1,3,-1,-1,-1,-1,-1,4]

test_input = { "heights": [3,1,2,4,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,4,3,1,2,3,4,3,2,2,3,4,3,3,3,3,4,4,4,4,4,4]

test_input = { "heights": [3,1,2,5,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,4,3,1,2,3,4,3,2,2,3,4,3,3,3,3,-1,4,4,4,-1,4]

test_input = { "heights": [3,1,4,2,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,4,4,2,1,2,3,4,2,2,2,4,4,4,3,4,3,4,4,4,4,4,4]

test_input = { "heights": [3,1,4,5,2], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,-1,2,1,2,3,4,2,2,2,3,-1,3,3,3,3,-1,-1,4,-1,-1,4]

test_input = { "heights": [3,1,5,2,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,4,4,2,1,2,3,4,2,2,2,-1,-1,4,3,-1,3,4,4,4,-1,4,4]

test_input = { "heights": [3,1,5,4,2], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,-1,2,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,-1,-1,4,-1,-1,4]

test_input = { "heights": [3,2,1,4,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,4,3,1,3,3,4,3,3,2,3,4,3,3,3,3,4,4,4,4,4,4]

test_input = { "heights": [3,2,1,5,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,4,3,1,3,3,4,3,3,2,3,4,3,3,3,3,-1,4,4,4,-1,4]

test_input = { "heights": [3,2,4,1,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,4,4,2,1,2,4,4,2,2,2,4,4,4,4,4,3,4,4,4,4,4,4]

test_input = { "heights": [3,2,4,5,1], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,-1,2,1,2,3,-1,2,2,2,3,-1,3,3,3,3,-1,-1,-1,-1,-1,4]

test_input = { "heights": [3,2,5,1,4], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,4,4,2,1,2,4,4,2,2,2,-1,-1,4,4,-1,3,4,4,4,-1,4,4]

test_input = { "heights": [3,2,5,4,1], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,-1,2,1,2,3,-1,2,2,2,-1,-1,3,3,-1,3,-1,-1,-1,-1,-1,4]

test_input = { "heights": [3,4,1,2,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,4,4,4,1,1,4,4,4,4,4,2,3,4,4,4,3,3,4,4,4,4,4,4]

test_input = { "heights": [3,4,1,5,2], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,-1,1,1,3,3,-1,3,3,2,3,4,3,3,3,3,-1,-1,-1,4,-1,4]

test_input = { "heights": [3,4,2,1,5], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,4,4,4,1,1,4,4,4,4,4,2,4,4,4,4,4,3,4,4,4,4,4,4]

test_input = { "heights": [3,4,2,5,1], "queries": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }
assert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,-1,1,1,3,3,-1,3,3,2,3,-1,3,3,3,3,-1,-1,-1,-1,-1,4]