#include <bits/stdc++.h>
using namespace std;
int main()
  {int N; cin >> N;
  vector<int> cs(1e5 + 1);
  auto s = 0LL;
  vector<int> A(N); for (auto &a: A) {cin >> a; ++cs[a]; s += a;}
  int Q; cin >> Q;
  while (Q--)
    {int B, C; cin >> B >> C;
    auto b = cs[B]; cs[B] = 0; cs[C] += b;
    cout << (s += b * (C - B)) << endl;}}