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