#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (long long)(res * x);
    y = y >> 1;
    if (x <= 100000000) x = (long long)(x * x);
  }
  return res;
}
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  map<long long, long long> m;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    m[a[i]]++;
    sum += a[i];
  }
  long long b[n];
  long long c[n];
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (long long i = 0; i < q; i++) {
    sum += (-b[i] * m[b[i]] + c[i] * m[b[i]]);
    cout << sum << "\n";
    m[c[i]] += m[b[i]];
    m[b[i]] = 0;
  }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
  return 0;
}
