#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 20;
const int MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  int a[100010] = {};
  long long res = 0;
  for (int i = 0; i < (n); i++) {
    int x;
    cin >> x;
    a[x]++;
    res += x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    res -= b * a[b];
    res += c * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << res << endl;
  }
  return 0;
}
