#define TASKNAME "connections"
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>
 
#define EPS (1e-9)
#define INF (int(1e9))
#define INFLONG (long long)(1e18)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)a.size()
#define fst first
#define snd second
#define y1 osrughosduvgarligybakrybrogvba
#define y0 aosfigdalrowgyalsouvgrlvygalri                               
#define mp make_pair
#define pb push_back
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <bool> vb;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef vector <pii> vpii;

const int maxn = 5010;

struct seg
{
  int l, r;
  int id;
  seg() {l = r = id = 0;}
  seg(int l, int r, int id) : l(l), r(r), id(id) {}
};

inline bool operator < (const seg &a, const seg &b) {return a.l < b.l;}

int n;
seg ev[maxn];
int ans[maxn];

inline bool less_r(const seg &a, const seg &b)
{
  return a.r < b.r;
}

inline int lis(vector <seg> &a, vector <seg> &b)
{
  vi maxl(sz(b), 1);
  for (int i = 0; i < sz(b); i++)
    for (int j = 0; j < i; j++)
      if (b[j].r < b[i].r && maxl[j] + 1 > maxl[i])
        maxl[i] = maxl[j] + 1;
  for (int i = 1; i < sz(b); i++)
    maxl[i] = max(maxl[i], maxl[i - 1]);
                         
  sort(all(a), less_r);
  vi maxr(sz(a) + 1, 1);
  maxr[sz(a)] = 0;
  for (int i = sz(a) - 1; i >= 0; i--)
    for (int j = i + 1; j < sz(a); j++)
      if (a[i].l < a[j].l && maxr[j] + 1 > maxr[i])
        maxr[i] = maxr[j] + 1;
  for (int i = sz(a) - 1; i >= 0; i--)
    maxr[i] = max(maxr[i], maxr[i + 1]);

  int answer = maxr[0];
  for (int i = 0; i < sz(b); i++)
  {
    int idx = -1;
    for (int j = 0; j < sz(a); j++)
      if (a[j].r > b[i].l)
      {
        idx = j;
        break;
      }
    int mr = 0;
    if (idx != -1)
      mr = maxr[idx];
    answer = max(answer, maxl[i] + mr);
  }
  return answer;
}

int main()
{
  freopen(TASKNAME".in", "r", stdin);
  freopen("stress2.out", "w", stdout);
  scanf("%d", &n);
  assert(n <= 500);
  for (int i = 0; i < n; i++)
  {
    scanf("%d%d", &ev[i].l, &ev[i].r);
    ev[i].id = i;
  }
  sort(ev, ev + n);
  for (int i = 0; i < n; i++)
  {
    ans[ev[i].id] = 0;
    vector <seg> ls, rs;
    for (int j = 0; j < i; j++)
      if (ev[j].l < ev[i].l && ev[i].l < ev[j].r && ev[j].r < ev[i].r)
        ls.pb(ev[j]);
    for (int j = i + 1; j < n; j++)
    {
      if (ev[j].l >= ev[i].r)
        break;
      if (ev[i].l < ev[j].l && ev[j].l < ev[i].r && ev[j].r > ev[i].r)
        rs.pb(ev[j]);
    }
    int best = lis(ls, rs);
    if (best + 1 > ans[ev[i].id])   
      ans[ev[i].id] = best + 1;
  }

  int k;
  scanf("%d", &k);
  assert(k <= 500);                                   
  for (int i = 0; i < k; i++)
  {
    int id;
    scanf("%d", &id);
    printf("%d\n", ans[--id]);
  }  
  return 0;
}
