This problem has nothing to do with Little Chris. It is about hill climbers instead (and Chris definitely isn't one).

There are n hills arranged on a line, each in the form of a vertical line segment with one endpoint on the ground. The hills are numbered with numbers from 1 to n from left to right. The i-th hill stands at position xi with its top at height yi. For every two hills a and b, if the top of hill a can be seen from the top of hill b, their tops are connected by a rope. Formally, the tops of two hills are connected if the segment connecting their top points does not intersect or touch any of the other hill segments. Using these ropes, the hill climbers can move from hill to hill.

There are m teams of climbers, each composed of exactly two members. The first and the second climbers of the i-th team are located at the top of the ai-th and bi-th hills, respectively. They want to meet together at the top of some hill. Now, each of two climbers move according to the following process:

  1. if a climber is at the top of the hill where the other climber is already located or will come eventually, the former climber stays at this hill; 
  2. otherwise, the climber picks a hill to the right of his current hill that is reachable by a rope and is the rightmost possible, climbs this hill and continues the process (the climber can also climb a hill whose top is lower than the top of his current hill). 

<image>

For each team of climbers, determine the number of the meeting hill for this pair!

Input

The first line of input contains a single integer n (1 ≤ n ≤ 105), the number of hills. The next n lines describe the hills. The i-th of them contains two space-separated integers xi, yi (1 ≤ xi ≤ 107; 1 ≤ yi ≤ 1011), the position and the height of the i-th hill. The hills are given in the ascending order of xi, i.e., xi < xj for i < j.

The next line of input contains a single integer m (1 ≤ m ≤ 105), the number of teams. The next m lines describe the teams. The i-th of them contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n), the numbers of the hills where the climbers of the i-th team are located. It is possible that ai = bi.

Output

In a single line output m space-separated integers, where the i-th integer is the number of the meeting hill for the members of the i-th team.

Examples

Input

6
1 4
2 1
3 2
4 3
6 4
7 4
3
3 1
5 6
2 3


Output

5 6 3 
#include <bits/stdc++.h>
using namespace std;
struct point {
  long long x, y;
  point() {}
  point(long long _x, long long _y) {
    x = _x;
    y = _y;
  }
};
inline long long CCW(point a, point b, point c) {
  long long a1 = b.x - a.x, b1 = b.y - a.y;
  long long a2 = c.x - b.x, b2 = c.y - b.y;
  return a1 * b2 - a2 * b1;
}
const int maxN = 1e5 + 5;
int n, m;
point p[maxN];
vector<int> head[maxN];
int st[maxN], top;
int parent[maxN][20], h[maxN];
void DFS(int u) {
  for (int i = 0; i < (int)head[u].size(); ++i) {
    int v = head[u][i];
    parent[v][0] = u;
    h[v] = h[u] + 1;
    DFS(v);
  }
}
void Init() {
  m = (int)log2(n) + 1;
  for (int j = 1; j <= m; ++j)
    for (int i = 1; i <= n; ++i) parent[i][j] = parent[parent[i][j - 1]][j - 1];
}
void Jump(int &u, int x) {
  for (int i = m; i >= 0; --i)
    if (x >= (1 << i)) {
      u = parent[u][i];
      x -= (1 << i);
    }
}
int LCA(int u, int v) {
  if (h[u] > h[v])
    Jump(u, h[u] - h[v]);
  else
    Jump(v, h[v] - h[u]);
  if (u == v) return u;
  for (int i = m; i >= 0; --i)
    if (parent[u][i] != parent[v][i]) {
      u = parent[u][i];
      v = parent[v][i];
    }
  return parent[u][0];
}
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    long long x, y;
    scanf("%I64d%I64d", &x, &y);
    p[i] = point(x, y);
  }
  head[n].push_back(n - 1);
  top = 2;
  st[1] = n;
  st[2] = n - 1;
  for (int i = n - 2; i >= 1; --i) {
    while (top >= 2 && CCW(p[st[top - 1]], p[st[top]], p[i]) < 0) --top;
    head[st[top]].push_back(i);
    st[++top] = i;
  }
  DFS(n);
  Init();
  int q = 0;
  scanf("%d", &q);
  while (q--) {
    int u, v;
    scanf("%d%d", &u, &v);
    printf("%d ", LCA(u, v));
  }
  return 0;
}
