#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long m) {
  long long r = 1;
  for (; y; y >>= 1) {
    if (y & 1) r = r * x % m;
    x = x * x % m;
  }
  return r;
}
const long long mod = 1e9 + 7;
const long double pi = 3.14159265358979;
int run_test() {
  int n;
  cin >> n;
  map<int, int> mp;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum += a;
    mp[a]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum -= b * mp[b];
    sum += c * mp[b];
    cout << sum << "\n";
    mp[c] += mp[b];
    mp[b] = 0;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long t;
  t = 1;
  while (t--) {
    run_test();
  }
}
