#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long arr[100001];
  for (long long i = 0; i < 100001; i++) {
    arr[i] = 0;
  }
  for (long long i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    arr[tmp]++;
  }
  long long Q;
  cin >> Q;
  for (long long i = 0; i < Q; i++) {
    long long B, C;
    cin >> B >> C;
    arr[C] += arr[B];
    arr[B] = 0;
    long long S = 0;
    for (long long i = 0; i < 100001; i++) {
      S += i * arr[i];
    }
    cout << S << endl;
  }
  return 0;
}
