#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int z[n];
  for (int i = 0; i < n; i++) {
    cin >> z[i];
  }
  int k;
  cin >> k;
  while (k--) {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < n; i++) {
      if (z[i] == a) {
        z[i] = b;
      }
    }
    int s = 0;
    for (int i = 0; i < n; ++i) {
      s += z[i];
    }
    cout << s << '\n';
  }
  return 0;
}
