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