#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)(1e9 + 7);
long long power(long long x, long long n) {
  if (n == 0) return 1;
  if (n == 1) return x % mod;
  if (n % 2 == 0) {
    long long y = power(x, n / 2) % mod;
    return (y * y) % mod;
  }
  if (n & 1) {
    long long y = power(x, n - 1);
    return (x % mod * y % mod) % mod;
  }
  return 0;
}
bool is_power_2(long long n) { return log2(n) == floor(log2(n)); }
bool is_prime(long long n) {
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return 0;
  return 1;
}
long long dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
long long dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const long long maxn = 100005;
void solve() {
  long long n, i, j, k, m;
  cin >> n;
  long long ar[n];
  map<long long, vector<long long>> make_pair;
  long long sum = 0;
  for (i = 0; i < n; i++) {
    cin >> ar[i];
    sum += ar[i];
    make_pair[ar[i]].push_back(i);
  }
  long long q;
  cin >> q;
  while (q--) {
    long long a, b;
    cin >> a >> b;
    m = (long long)make_pair[a].size();
    while ((long long)make_pair[a].size()) {
      make_pair[b].push_back(make_pair[a].back());
      make_pair[a].pop_back();
    }
    sum -= a * m;
    sum += b * m;
    cout << sum << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) solve();
  return 0;
}
