#include <bits/stdc++.h>
using namespace std;
bool IsPrime(long long num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (long long i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> a[i];
  }
  long long q;
  cin >> q;
  vector<long long> b(q), c(q);
  for (long long i = 0; i < (long long)(q); i++) {
    cin >> b[i] >> c[i];
    std::vector<long long>::iterator itr;
    while (true) {
      itr = std::find(a.begin(), a.end(), b[i]);
      if (itr == a.end()) {
        break;
      } else {
        const int index = std::distance(a.begin(), itr);
        a[index] = c[i];
      }
    }
    cout << std::accumulate(a.begin(), a.end(), 0LL) << endl;
  }
  return 0;
}
