#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(100001, 0);
  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    vec[num] += 1;
  }
  int64_t sum = 0;
  for (int i = 0; i < 100001; i++) {
    sum += (vec[i] * i);
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    int count = vec[B];
    vec[B] = 0;
    vec[C] += count;
    sum -= count * B;
    sum += count * C;
    cout << sum << endl;
  }
  return 0;
}
