#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long N, Q;
  cin >> N;
  long long A[100000];
  for (long long i = 0; i < (long long)(100000); i++) {
    A[i] = 0;
  }
  long long index, sum = 0;
  for (long long i = 0; i < (long long)(N); i++) {
    cin >> index;
    A[index]++;
    sum += index;
  }
  cin >> Q;
  long long B, C;
  for (long long i = 0; i < (long long)(Q); i++) {
    cin >> B >> C;
    long long diff = (C - B) * A[B];
    sum += diff;
    A[C] += A[B];
    A[B] = 0;
    cout << sum << endl;
  }
  return 0;
}
