#include <bits/stdc++.h>
using namespace std;
int dr[4] = {0, 0, -1, 1};
int dc[4] = {-1, 1, 0, 0};
const int N = 100;
int main() {
  int n, q, a, b;
  cin >> n;
  long long sum = 0, x;
  map<long long, int> mm;
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    sum += x;
    mm[x]++;
  }
  cin >> q;
  while (q--) {
    cin >> a >> b;
    sum -= (a * mm[a]);
    sum += (b * mm[a]);
    mm[b] += mm[a];
    mm[a] = 0;
    cout << sum << endl;
  }
  return 0;
}
