#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int Q, N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  cin >> Q;
  vector<int> b(Q), c(Q);
  for (int i = 0; i < Q; i++) cin >> b[i] >> c[i];
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < N; j++) {
      if (a[j] == b[i]) a[j] = c[i];
    }
    ll sum = 0;
    for (int j = 0; j < N; j++) sum += a[j];
    cout << sum << endl;
  }
}
