#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7, N = 205001;
long long mm(long long x, long long y) {
  x %= M, y %= M;
  return (x * y) % M;
}
long long po(long long x, long long y) {
  if (!y) return 1;
  long long a = po(x, y / 2) % M;
  if (y % 2) return mm(a, mm(a, x));
  return mm(a, a);
}
void solve() {
  long long n, m, i, k, s = 0, x, y;
  cin >> n;
  long long a[n];
  map<long long, long long> mp;
  for (i = 0; 0 < n ? i < n : i > n; 0 < n ? i += 1 : i -= 1) {
    cin >> a[i];
    s += a[i];
    mp[a[i]]++;
  }
  cin >> m;
  while (m--) {
    cin >> x >> y;
    long long f = mp[x];
    mp[y] += f;
    s += f * (y - x);
    cout << s << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
