#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long int MOD = 1000000007;
const int M = 1000005;
int main(void) {
  int n;
  cin >> n;
  vector<int> cnt(M);
  long long int sum = 0;
  for (int i = 0; i < (n); ++i) {
    int a;
    cin >> a;
    cnt[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    cnt[c] += cnt[b];
    sum -= b * cnt[b];
    sum += c * cnt[b];
    cnt[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
