#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void jpg() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long mpow(long long base, long long exp);
int32_t main() {
  jpg();
  long long n;
  cin >> n;
  map<long long, long long> m;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    long long ai;
    cin >> ai;
    ++m[ai];
    sum += ai;
  }
  long long Q;
  cin >> Q;
  while (Q--) {
    long long b, c;
    cin >> b >> c;
    if (m.find(b) == m.end()) {
      cout << sum << "\n";
      continue;
    }
    long long tmp = m[b];
    sum -= tmp * b;
    sum += tmp * c;
    m.erase(b);
    m[c] += tmp;
    cout << sum << "\n";
  }
}
long long mpow(long long base, long long exp) {
  base %= 998244353;
  long long result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((long long)result * base) % 998244353;
    base = ((long long)base * base) % 998244353;
    exp >>= 1;
  }
  return result;
}
