#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int a, b, n, i, t, tmp, sum = 0, k;
  map<int, int> mp;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> a;
    mp[a]++;
    sum += a;
  }
  cin >> n;
  while (n--) {
    cin >> a >> b;
    k = mp[a];
    if (a < b) {
      sum = sum + b * k - a * k;
      cout << sum << endl;
      mp[b] = k + mp[b];
      mp[a] = 0;
    } else if (a > b) {
      sum = sum - (a - b) * k;
      cout << sum << endl;
      mp[b] = k + mp[b];
      mp[a] = 0;
    } else
      cout << sum << endl;
  }
  return 0;
}
