#include <bits/stdc++.h>
using namespace std;
long long num_counter[1001001];
int main() {
  long long N;
  cin >> N;
  for (long long i = 1; i <= N; ++i) {
    long long j;
    cin >> j;
    num_counter[j]++;
  }
  long long ans = 0;
  for (int i = 1; i <= N; ++i) {
    ans += (i * num_counter[i]);
  }
  long long Q;
  cin >> Q;
  for (long long i = 0; i < Q; ++i) {
    long long B, C;
    cin >> B >> C;
    long long tmp = num_counter[B];
    ans -= (B * num_counter[B]);
    long long plus = (C * tmp);
    ans += plus;
    cout << ans << endl;
    num_counter[C] += num_counter[B];
    num_counter[B] = 0;
  }
}
