#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, q;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cin >> q;
  vector<long long> b(q);
  vector<long long> c(q);
  for (int i = 0; i < q; ++i) {
    cin >> b[i] >> c[i];
  }
  long long sum = 0;
  for (int i = 0; i < q; ++i) {
    for (int j = 0; j < n; ++j) {
      if (b[i] == a[j]) {
        a[j] = c[i];
      }
      sum += a[j];
    }
    cout << sum << '\n';
    sum = 0;
  }
  return 0;
}
