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