#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
int A[1000010]{0};
int main() {
  int N;
  cin >> N;
  map<int, int> A;
  for (int i = 0; i < N; ++i) {
    int el;
    cin >> el;
    A[el]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int B, C;
    cin >> B >> C;
    ll tmp = A[B];
    A.erase(B);
    A[C] += tmp;
    ll res = 0;
    for (auto it = A.begin(); it != A.end(); ++it) {
      if (it->second == 0) continue;
      res += (it->first * it->second);
    }
    cout << res << endl;
  }
  return 0;
}
