#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const long long INF = 1000000001;
const long long N = 100001;
const long double PI = 3.141593;
long double powm(long long base, long long exp) {
  long long ans = 1;
  while (exp) {
    if (exp & 1) ans = (ans * base) % mod;
    exp >>= 1, base = (base * base) % mod;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, q;
  cin >> n;
  map<long long, long long> m;
  long long s = 0;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    m[x]++;
    s += x;
  }
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long a, b;
    cin >> a >> b;
    m[b] += m[a];
    s -= (a * m[a]);
    s += (m[a] * b);
    cout << s << endl;
  }
}
