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