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