#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  int sum = 0;
  vector<long> num(110000, 0);
  long a, b, c = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    sum += a;
    num[a]++;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> b >> c;
    sum += (c - b) * num[b];
    num[c] += num[b];
    num[b] = 0;
    cout << sum << endl;
  }
}
