#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  {
    int i = 0, j = 0, k = 0, n = 0, tmp = 0;
    cin >> n;
    map<long long, long long> m;
    for (i = 0; i <= n - 1; i++) {
      cin >> tmp;
      m[tmp]++;
    }
    long long sum = 0;
    for (auto it : m) {
      sum += it.first * it.second;
    }
    int q = 0;
    cin >> q;
    while (q--) {
      long long a, b;
      cin >> a >> b;
      sum -= (a * m[a]);
      sum += (m[a] * b);
      m[b] += m[a];
      m.erase(m[a]);
      cout << sum << '\n';
    }
  }
  return 0;
}
