#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long modi(long long a, long long m) { return power(a, m - 2, m); }
int32_t main() {
  long long n;
  cin >> n;
  vector<long long> v(100001, 0);
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    v[a]++;
    sum += a;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long a, b;
    cin >> a >> b;
    long long x = v[a];
    long long y = v[b];
    v[a] = 0;
    v[b] += x;
    sum = sum - x * a + y * b;
    cout << sum << endl;
  }
}
