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