#define TASKNAME "connections"
#include <cstdio>
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <cassert>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>
 
#define EPS (1e-9)
#define INF (int(1e9))
#define INFLONG ((long long)(1e18))
#define sqr(a) ((a) * (a))
#define all(a) (a).begin(), (a).end()
#define zero(a) memset(a, 0, sizeof(a))
#define abs(a) (((a) < 0) ? -(a) : (a))
#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 next dlkjdslfkdj
#define prev dsdflksdfjl
#define hash lkdfjldskfj
#define pi 3.1415926535897932384626433832795
#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 = 10;

int n, k;
int l[maxn], r[maxn];

inline bool bit(int msk, int b)
{
  return msk & (1 << b);
}

inline bool intersect(int i, int j)
{
  return l[i] < l[j] && l[j] < r[i] && r[j] > r[i];
}

int main()
{
  freopen(TASKNAME".in", "r", stdin);
  freopen("stress.out", "w", stdout);
  scanf("%d", &n);
  assert(n <= 10);
  for (int i = 0; i < n; i++)
    scanf("%d%d", &l[i], &r[i]);
  scanf("%d", &k);
  assert(k <= 10);
  for (int it = 0; it < k; it++)
  {
    int id;
    scanf("%d", &id);
    --id;
    int max_ans = 0;
    for (int msk = 0; msk < (1 << n); msk++)
    {
      if (!bit(msk, id))
        continue;
      int bits = 0;
      for (int i = 0; i < n; i++)
        bits += bit(msk, i);

      bool ok = 1;
      for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
          if (bit(msk, i) && bit(msk, j) && !intersect(i, j) && !intersect(j, i))
            ok = 0;
      if (ok && max_ans < bits)
        max_ans = bits;
    }
    printf("%d\n", max_ans);
  }                           
  return 0;
}

