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