#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int n, q, temp, s;
int main() {
  cin >> n;
  vector<int> a(100000);
  for (int i = 0; i < (n); ++i) {
    cin >> temp;
    temp--;
    a[temp]++;
  }
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < (q); ++i) {
    cin >> b[i] >> c[i];
    b[i]--;
    c[i]--;
  }
  s = 0;
  for (int i = 0; i < (100000); ++i) {
    s += a[i] * (i + 1);
  }
  for (int i = 0; i < (q); ++i) {
    s -= a[b[i]] * (b[i] + 1);
    s += a[b[i]] * (c[i] + 1);
    a[c[i]] += a[b[i]];
    a[b[i]] = 0;
    cout << s << endl;
  }
  return 0;
}
