#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A.at(i);
  }
  int q;
  cin >> q;
  vector<int> B(q);
  vector<int> C(q);
  for (int i = 0; i < q; i++) {
    cin >> B.at(i) >> C.at(i);
  }
  int sum = 0;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (A.at(j) == B.at(i)) {
        A.at(j) = C.at(i);
      }
    }
    sum = 0;
    for (int j = 0; j < n; j++) {
      sum += A.at(j);
    }
    cout << sum << endl;
  }
}
