#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int N;
  cin >> N;
  map<long long, long long> cnt;
  long long sum = 0;
  for (int i = 0; i < (N); i++) {
    long long cur;
    cin >> cur;
    cnt[cur]++;
    sum += cur;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < (Q); i++) {
    long long B, C;
    cin >> B >> C;
    sum -= cnt[B] * B;
    sum += cnt[C] * C;
    cnt[C] += cnt[B];
    cnt[B] = 0;
    cout << sum << nl;
  }
  return 0;
}
