#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long n, k, a, count;
  unsigned long long kount[100000], b[100000], c[100000];
  bool is[100000];
  count = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (!is[a]) {
      kount[a] = 1;
      is[a] = true;
    } else {
      kount[a]++;
    }
    count += a;
  }
  cin >> k;
  for (int i = 0; i < (k); i++) cin >> b[i] >> c[i];
  for (int i = 0; i < k; i++) {
    count += (c[i] - b[i]) * kount[b[i]];
    if (is[c[i]]) {
      kount[c[i]] += kount[b[i]];
    } else {
      is[c[i]] = true;
      kount[c[i]] = kount[b[i]];
    }
    kount[b[i]] = 0;
    cout << count << endl;
  }
}
