#include <bits/stdc++.h>
using namespace std;

int n, k;

typedef struct{
  int num;
  int data[4];
} Syori;



queue<int> graph[50050];
int izon[50050];
Syori data[50050];

Syori syori[24] = {};
int syoriTable[4][4][4][4];
Syori syoritmp;
int scnt = 0;

int make(int i, int bit){
  if(i == 4){
    syori[scnt] = syoritmp;
    syoriTable[syoritmp.data[0]][syoritmp.data[1]][syoritmp.data[2]][syoritmp.data[3]] = scnt;
    scnt++;
  }

  for(int j = 0;j < 4;j++){
    if((bit & (1 << j)) == 0){
      syoritmp.data[i] = j;
      make(i+1,bit | (1 << j));
    }
  }

  return 0;
}

Syori f[50050];


Syori segTree[24][200000] = {};
int segSize;

bool big(Syori a, Syori b, int i){
  if(a.data[syori[i].data[0]] == b.data[syori[i].data[0]]){
    if(a.data[syori[i].data[1]] == b.data[syori[i].data[1]]){
      if(a.data[syori[i].data[2]] == b.data[syori[i].data[2]]){
        return a.data[syori[i].data[3]] > b.data[syori[i].data[3]];
      }else{
        return a.data[syori[i].data[2]] > b.data[syori[i].data[2]];
      }
    }else{
      return a.data[syori[i].data[1]] > b.data[syori[i].data[1]];
    }
  }else{
    return a.data[syori[i].data[0]] > b.data[syori[i].data[0]];
  }
}

Syori nu;

void init(){
  segSize = 1;
  while(segSize < n){
    segSize *= 2;
  }

  nu.data[0] = 0;
  nu.data[1] = 0;
  nu.data[2] = 0;
  nu.data[3] = 0;

  for(int i = 0;i < 24;i++){
    for(int j = 0;j < segSize;j++){
      if(j < n && izon[j] == 0){
        segTree[i][segSize-1+j] = f[j];
        segTree[i][segSize-1+j].num = j;
      }else{
        segTree[i][segSize-1+j] = nu;
        segTree[i][segSize-1+j].num = j;
      }
    }
  }

  for(int i = 0;i < 24;i++){
    for(int j = segSize-2;j >= 0;j--){
      if(big(segTree[i][j*2+1],segTree[i][j*2+2],i)){
        segTree[i][j] = segTree[i][j*2+1];
      }else{
        segTree[i][j] = segTree[i][j*2+2];
      }
    }
  }

  return;
}

void insert(int x){

  int j;

  for(int i = 0;i < 24;i++){
    j = segSize-1+x;
    segTree[i][j] = f[x];
    segTree[i][j].num = x;
    while(j > 0){
      j = (j - 1) /2;
      if(big(segTree[i][j*2+1],segTree[i][j*2+2],i)){
        segTree[i][j] = segTree[i][j*2+1];
      }else{
        segTree[i][j] = segTree[i][j*2+2];
      }
    }
  }
}


void del(int x){
  int j;
  for(int i = 0;i < 24;i++){
    j = segSize-1+x;
    segTree[i][j] = nu;
    while(j > 0){
      j = (j - 1) /2;
      if(big(segTree[i][j*2+1],segTree[i][j*2+2],i)){
        segTree[i][j] = segTree[i][j*2+1];
      }else{
        segTree[i][j] = segTree[i][j*2+2];
      }
    }
  }
  return;
}

int getData(int i){
  return segTree[i][0].num;
}


int main(){
  cin >> n >> k;

  for(int i = 0;i < n;i++){
    for(int j = 0;j < 4;j++){
      if(j < k){
        cin >> f[i].data[j];
      }else{
        f[i].data[j] = 0;
      }
    }
  }

  int d; cin >> d;
  for(int i = 0;i < d;i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    izon[b]++;
    graph[a].push(b);
  }

  for(int i = 0;i < 4;i++){
    if(i < k){
      cin >> data[0].data[i];
      data[0].data[i]--;
    }else{
      data[0].data[i] = i;
    }
  }

  int r;
  cin >> r;
  int m;
  int tmp = 0;

  for(int i = 0;i < r;i++){
    cin >> m;
    for(int j = tmp+1;j < m;j++){
      data[j] = data[j-1];
    }
    for(int j = 0;j < 4;j++){
      if(j < k){
        cin >> data[m].data[j];
        data[m].data[j]--;
      }else{
        data[m].data[j] = j;
      }
    }
    tmp = m;
  }

  for(int j = tmp+1;j < n;j++){
    data[j] = data[j-1];
  }

  make(0,0);

  init();

  queue<int> ans;
  for(int i = 0;i < n;i++){
    int tmpi = getData(syoriTable[data[i].data[0]][data[i].data[1]][data[i].data[2]][data[i].data[3]]);
    ans.push(tmpi);
    del(tmpi);
    while(!graph[tmpi].empty()){
      izon[graph[tmpi].front()]--;
      if(izon[graph[tmpi].front()] == 0){
        insert(graph[tmpi].front());
      }
      graph[tmpi].pop();
    }
  }

  for(int i = 0;i < n;i++){
    cout << ans.front()+1 << endl;
    ans.pop();
  }
  return 0;
}



Measured memory_bytes: 100628