#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  long long *A, *B, *C;
  long long sum = 0;
  cin >> N;
  A = new long long[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cin >> Q;
  B = new long long[Q];
  C = new long long[Q];
  for (int j = 0; j < Q; j++) {
    cin >> B[j] >> C[j];
  }
  for (int k = 0; k < Q; k++) {
    for (int l = 0; l < Q; l++) {
      if (A[l] == B[k]) {
        A[l] = C[k];
      }
    }
    for (int p = 0; p < N; p++) {
      sum += A[p];
    }
    cout << sum << endl;
    sum = 0;
  }
  return 0;
}
