#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); i++) {
    cin >> a.at(i);
  }
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < (q); i++) {
    cin >> b.at(i);
    cin >> c.at(i);
  }
  vector<long long> s(q);
  for (int i = 0; i < (q); i++) {
    long long sum = 0;
    for (int j = 0; j < (n); j++) {
      if (b.at(i) == a.at(j)) {
        a.at(j) = c.at(i);
      }
    }
    sum = accumulate(a.begin(), a.end(), 0);
    cout << sum << endl;
  }
  return 0;
}
