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