#include <bits/stdc++.h>
using namespace std;
int main() {
  int frek[100001] = {0};
  int n, sum = 0;
  cin >> n;
  for (int i = 0, a; i < n; i++) cin >> a, sum += a, frek[a]++;
  int Q;
  cin >> Q;
  for (int i = 0, prev, to; i < Q; i++) {
    cin >> prev >> to;
    sum -= frek[prev] * prev;
    sum += frek[prev] * to;
    frek[to] += frek[prev];
    frek[prev] = 0;
    cout << sum << endl;
  }
}
