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