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