#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  int Q;
  cin >> Q;
  int B[Q];
  for (int i = 0; i < Q; i++) cin >> B[i];
  int C[Q];
  for (int i = 0; i < Q; i++) cin >> C[i];
  for (int i = 0; i < Q; i++) {
    int t = B[i];
    B[i] = C[i];
    for (int j = 0; j < N; j++) {
      if (A[j] == t) A[j] = B[i];
    }
    int sum = 0;
    for (int m = 0; m < N; m++) sum += A[m];
    cout << sum << endl;
  }
}
