#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  int N;
  cin >> N;
  int temp;
  vector<int> num(100001, 0);
  for (int i = 0; i < (int)(N); i++) {
    cin >> temp;
    num[temp]++;
  }
  ll output = 0;
  for (int i = 0; i < (int)(100001); i++) {
    output += i * num[i];
  }
  int Q;
  cin >> Q;
  vector<int> B(Q, 0);
  vector<int> C(Q, 0);
  for (int i = 0; i < (int)(Q); i++) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < (int)(Q); i++) {
    if (num[B[i]] == 0) {
      cout << output << endl;
      continue;
    }
    output -= B[i] * num[B[i]];
    output += C[i] * num[B[i]];
    num[C[i]] += num[B[i]];
    num[B[i]] = 0;
    cout << output << endl;
  }
}
