#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int q;
  cin >> q;
  vector<int> b(q), c(q), s(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];
      s[i] += a[j];
    }
  }
  for (int i = 0; i < q; i++) cout << s[i] << endl;
  return 0;
}
