#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y,
                    long long int p = 1000000007) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
const long long int N = 1e5 + 1;
long long int n, a[N], sm = 0, b, c, q;
void solve() {
  cin >> n;
  map<long long int, long long int> mpp;
  for (long long int i = 0; i < n; i++) cin >> a[i], sm += a[i], mpp[a[i]]++;
  cin >> q;
  for (long long int i = 0; i < q; i++) {
    cin >> b >> c;
    mpp[c] += mpp[b];
    sm += (mpp[b] * (c - b));
    cout << sm << '\n';
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
