#include <bits/stdc++.h>
using namespace std;
long long power(long long num, long long g, long long mod) {
  if (g == 0) return 1;
  if (g % 2 == 1) return (num * power((num * num) % mod, g / 2, mod)) % mod;
  return power((num * num) % mod, g / 2, mod);
}
int main() {
  int n;
  cin >> n;
  int a[n];
  unordered_map<int, int> make_pair;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    make_pair[a[i]]++;
    sum += a[i];
  }
  int q, b, c;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    int num;
    if (make_pair.find(b) == make_pair.end())
      num = 0;
    else
      num = make_pair[b];
    make_pair[b] = 0;
    make_pair[c] += num;
    sum += num * (c - b);
    cout << sum << '\n';
  }
}
