#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long count[100010];
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    long long x;
    cin >> x;
    sum += x;
    count[x]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    long long B, C;
    cin >> B >> C;
    sum += count[B] * (C - B);
    cout << sum << endl;
    count[C] += count[B];
    count[B] = 0;
  }
}
