#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
int a[N];
int q;
int f[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    f[x]++;
    sum += x;
  }
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= b * f[b];
    sum += f[b] * c;
    f[c] += f[b];
    f[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
