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