#include <bits/stdc++.h>
using namespace std;
long long power(long long b, long long e, long long m) {
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b % m, e / 2, m) % m;
  return power(b * b % m, e / 2, m);
}
long long power(long long b, long long e) {
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b, e / 2);
  return power(b * b, e / 2);
}
bool isPowerOfTwo(long long x) { return (x && !(x & (x - 1))); }
long long ldd(long long n) {
  for (long long i = 3; i * i <= n; i += 2)
    if (n % i == 0) return i;
}
void solve() {
  long long n, x;
  cin >> n;
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    mp[x]++;
  }
  long long ans = 0;
  for (auto i : mp) ans += i.first * i.second;
  long long q;
  cin >> q;
  while (q--) {
    long long a, b;
    cin >> a >> b;
    ans = ans - a * mp[a] + b * mp[a];
    if (mp.find(mp[b]) != mp.end())
      mp[b] += mp[a];
    else
      mp[b] = mp[a];
    cout << ans << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
