#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const char nl = '\n';
void sol() {
  int N;
  cin >> N;
  int ar[N];
  set<int> second;
  for (int i = 0; i < (N); i++) {
    cin >> ar[i];
    second.insert(ar[i]);
  }
  map<long long, long long> m;
  for (auto& x : second) {
    int countt = count(ar, ar + N, x);
    m[x] = countt;
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int B, C;
    cin >> B >> C;
    auto it = m.find(C);
    if (it != m.end()) {
      m[C] = m[C] + m[B];
      m.erase(B);
    } else {
      m[C] = m[B];
      m.erase(B);
    }
    int sum = 0;
    for (auto itr = m.begin(); itr != m.end(); ++itr) {
      sum = sum + itr->first * itr->second;
    }
    cout << sum << nl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T = 1;
  while (T--) {
    sol();
  }
  return 0;
}
