#include <bits/stdc++.h>
using namespace std;
long long gcd(long long s, long long t) {
  if (t == 0) return s;
  return gcd(t, s % t);
}
signed main() {
  long long n;
  cin >> n;
  long long m[100001];
  long long a[n];
  long long wkey = 0;
  for (long long i = 0; i < 100001; i++) {
    m[i] = 0;
  }
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    wkey += a[i];
  }
  long long w;
  cin >> w;
  long long b[w], c[w];
  for (long long i = 0; i < w; i++) {
    cin >> b[i] >> c[i];
  }
  long long ans;
  for (long long i = 0; i < w; i++) {
    wkey += (c[i] - b[i]) * m[b[i]];
    ans = m[b[i]];
    m[c[i]] += ans;
    cout << wkey << endl;
  }
}
