#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
int main() {
  int N, Q, B, C;
  cin >> N;
  long long ans = 0;
  int count[1000000] = {0};
  for (int i = 0; i < N; ++i) {
    long long tmp;
    cin >> tmp;
    ans += tmp;
    ++count[tmp];
  }
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    cin >> B >> C;
    if (count[B] != 0) {
      ans -= B * count[B];
      ans += C * count[B];
      count[C] += count[B];
      count[B] = 0;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
