#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long q;
  cin >> q;
  vector<long long> b(q);
  vector<long long> c(q);
  for (long long i = 0; i < q; i++) {
    cin >> b[i];
    cin >> c[i];
  }
  for (long long i = 0; i < q; i++) {
    for (long long j = 0; j < n; j++) {
      if (a[j] == b[i]) {
        a[j] = c[i];
      }
    }
    cout << accumulate(a.begin(), a.end(), 0) << endl;
  }
  cout << endl;
  return 0;
}
