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