#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
void solve() {
  int n;
  cin >> n;
  int a[N];
  memset(a, 0, sizeof(a));
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    int in;
    cin >> in;
    sum += in;
    ++a[in];
  }
  int nn;
  cin >> nn;
  while (nn--) {
    int b, c;
    cin >> b >> c;
    int bb = a[b];
    sum -= b * a[b];
    sum += c * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << sum << endl;
  }
}
int main(void) {
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}
