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