#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> mark;
  int n, mx = 0;
  long long sum = 0;
  cin >> n;
  int a[n + 2];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    mark[a[i]]++;
    mx = max(mx, a[i]);
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    sum -= (x * mark[x]);
    sum += (y * mark[x]);
    mark[y] += mark[x];
    mark[x] = 0;
    cout << sum << endl;
  }
}
