#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};
int main() {
  int n;
  cin >> n;
  long long a[10005] = {}, s = 0;
  for (int i = 0; i < n; i++) {
    long long ai;
    cin >> ai;
    a[ai]++;
    s += ai;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    s -= b * a[b];
    s += c * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << s << endl;
  }
  return 0;
}
