#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
const int N = 2e5 + 10;
int a[N];
int cnt[N];
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int B, C;
    cin >> B >> C;
    sum -= cnt[B] * B;
    sum += cnt[B] * C;
    cnt[C] = cnt[C] + cnt[B];
    cnt[B] = 0;
    cout << sum << '\n';
  }
  return 0;
}
