#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  int Q;
  cin >> Q;
  vector<pair<int, int>> BC(Q);
  for (int i = 0; i < Q; i++) cin >> BC[i].first >> BC[i].second;
  map<int, int> count;
  ull sum = 0;
  for (int a : A) {
    count[a]++;
    sum += a;
  }
  for (auto bc : BC) {
    sum += (bc.second - bc.first) * (count[bc.first]);
    count[bc.second] += count[bc.first];
    cout << sum << endl;
  }
}
