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