#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n;
  cin >> n;
  vi cnt(100001);
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    cnt[a]++;
  }
  ll sum = 0;
  for (int i = 0; i < (int)(100001); i++) {
    sum += i * cnt[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    sum -= b * cnt[b];
    sum -= c * cnt[c];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    sum += c * cnt[c];
    cout << sum << endl;
  }
}
