#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  multiset<int> A;
  int Q;
  int B[100050];
  int C[100050];
  int sum = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.insert(a);
    sum += a;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < Q; i++) {
    int count = A.count(B[i]);
    if (count > 0) {
      sum -= count * B[i];
      sum += count * C[i];
      for (int j = 1; j <= count; j++) A.insert(C[i]);
      A.erase(B[i]);
    }
    cout << sum << endl;
  }
}
