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