#include <bits/stdc++.h>
using namespace std;
char nth_letter(long long n) {
  assert(n >= 1 && n <= 26);
  return "abcdefghijklmnopqrstuvwxyz"[n - 1];
}
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long q;
  cin >> q;
  vector<long long> b(q);
  vector<long long> c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (int j = 0; j < q; j++) {
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == b[j]) {
        a[i] = c[j];
      }
      ans = ans + a[i];
    }
    cout << ans << endl;
  }
  return 0;
}
