/**
 * Standard checker: Template. Output and answer should be in the same format.
 */

#ifdef BURUNDUK
# include "my_testlib.h"
#else
# include "testlib.h"
#endif

#include <string>
#include <vector>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

const int maxN = (int)1e5;

ll sh = 0;                    
int H, n, l[maxN], h[maxN];
int cc, u[maxN];

void readInput( InStream &in )
{
  n = in.readInt(1, maxN);
  forn(i, n)
  {
    h[i] = in.readInt();
    l[i] = in.readInt();
    sh += h[i];
  }
  H = in.readInt();
}

int checkOutput( InStream &out )
{
  int x = out.readInt();
  cc++;
  ll cur_sh = sh;
  forn(i, x)
  {
    int j = out.readInt(1, n) - 1;
    if (u[j] == cc)
      out.quitf(_wa, "%d meets twice", j + 1);
    u[j] = cc;
    if (cur_sh + l[j] < H)
      out.quitf(_wa, "position %d: %d can not go out", i + 1, j + 1);
    cur_sh -= h[j];
  }
  return x;
}

int main(int argc, char *argv[])
{
  registerTestlibCmd(argc, argv);

  readInput(inf);

  int ja = checkOutput(ans);
  int ca = checkOutput(ouf);

  if (ca != ja)
    quitf(ca < ja ? _wa : _fail, "Contestant says %d, jury say %d", ca, ja);
  quitf(_ok, "OK (n = %d, answer = %d)", n, ja);
  return 0;
}
