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