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