#include <bits/stdc++.h>
using namespace std;
const int size = 1e5 + 1;
int s[size];
int main() {
std:
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  int t, i, b, c, sum = 0;
  cin >> n;
  for (i = 1; i <= n; i++) s[i] = 0;
  for (i = 0; i < n; i++) {
    cin >> t;
    s[t]++;
    sum += t;
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> b >> c;
    int oc = s[b];
    sum -= oc * b;
    sum += oc * c;
    s[b] = 0;
    s[c] += oc;
    cout << sum << "\n";
  }
}
