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