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