#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, tong = 0;
  map<long long, long long> a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[x]++;
    tong += x;
  }
  cin >> m;
  while (m--) {
    int c, b;
    cin >> b >> c;
    tong -= a[b] * b;
    tong += a[b] * c;
    a[c] += a[b];
    cout << tong << endl;
  }
}
