#include <bits/stdc++.h>   using namespace std;   bool psort(std::vector<long long int> p1, std::vector<long long int> p2) {     return p1[0] < p2[0];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m;     cin >> n;     std::vector<vector<long long int> > v(n, vector<long long int>(3));     for (int i = 0; i < n; ++i) {       cin >> v[i][0];     }     for (int i = 0; i < n; ++i) {       cin >> v[i][1];     }     for (int i = 0; i < n; ++i) {       cin >> v[i][2];     }     sort(v.begin(), v.end(), psort);     cin >> m;     long long int start[4] = {0};     for (int i = 0; i < m; ++i) {       long long int k, t, flag = 0;       cin >> t;       while (start[t] < n) {         if (v[start[t]][0] != -1) {           if (v[start[t]][1] == t || v[start[t]][2] == t) {             cout << v[start[t]][0] <<    ;             v[start[t]][0] = -1;             start[t]++;             flag = 1;             break;           }         }         start[t]++;       }       if (flag == 0) cout << -1 <<    ;     }     return 0;   }   