#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
int a[maxn], b[maxn], c[maxn], sum = 0;
int d[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    d[a[i]]++;
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> b[i] >> c[i];
    int x = d[b[i]];
    int y = x * (c[i] - b[i]);
    sum += y;
    d[b[i]] = 0;
    d[c[i]] += x;
    cout << sum << "\n";
  }
  return 0;
}
