#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, q;
  cin >> n;
  vector<long long> A;
  for (long long i = 0; i < n; i++) {
    long long temp;
    cin >> temp;
    A.push_back(temp);
  }
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    for (int l = 0; l < n; l++) {
      if (A[l] == b) A[l] = c;
    }
    cout << accumulate(A.begin(), A.end(), 0) << endl;
  }
  return 0;
}
