#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
vector<long long> fact, invfact;
long long modpower(long long x, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
long long inv(long long n) { return modpower(n, MOD - 2, MOD); }
void COMinit(long long k) {
  k++;
  fact.resize(k, 0);
  invfact.resize(k, 0);
  fact[0] = 1;
  for (long long i = 1; i < (k); i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }
  invfact[k - 1] = inv(fact[k - 1]);
  for (long long i = (k - 2); i >= 0; i--) {
    invfact[i] = invfact[i + 1] * (i + 1) % MOD;
  }
  return;
}
long long nCk(vector<long long> &fact, vector<long long> &invfact, long long n,
              long long k) {
  if (k < 0 || n < k) return 0LL;
  return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
}
long long com(long long n, long long k) {
  long long iv = 1;
  long long fa = 1;
  for (long long i = 0; i < (k); i++) {
    fa *= (n - i);
    fa %= MOD;
  }
  for (long long i = 1; i < (k + 1); i++) {
    iv *= inv(i);
    iv %= MOD;
  }
  return fa * iv % MOD;
}
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  vector<int> vec(100000, 0);
  for (long long i = 0; i < (n); i++) {
    int a;
    cin >> a;
    sum += a;
    vec[a - 1]++;
  }
  int q;
  cin >> q;
  for (long long i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    sum -= (b * vec[b - 1] + c * vec[c - 1]);
    vec[c - 1] += vec[b - 1];
    sum += vec[c - 1] * c;
    cout << sum << endl;
  }
  return 0;
}
