#include <bits/stdc++.h>
using namespace std;
int main() {
  long long tot = 0, n, q, b, c, i;
  cin >> n;
  long long a[n];
  vector<long long> res;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    for (i = 0; i < n; i++) {
      if (a[i] == b) a[i] = c;
      tot += a[i];
    }
    res.push_back(tot);
    tot = 0;
  }
  for (i = 0; i < res.size(); i++) {
    cout << res[i] << "\n";
  }
  return 0;
}
