#include <bits/stdc++.h>
using namespace std;
const int Nmax = 10000;
const int INF = 1000000000;
const int MOD = 1000000007;
int main() {
  long long unsigned int n;
  long long unsigned sum = 0;
  long long unsigned in_sum = 0;
  cin >> n;
  long long unsigned arr[100005];
  for (long long unsigned i = 0; i < n; i++) {
    long long unsigned x;
    cin >> x;
    arr[x]++;
    in_sum += x;
  }
  long long unsigned q;
  cin >> q;
  while (q--) {
    long long unsigned b, c;
    cin >> b >> c;
    in_sum -= b * arr[b];
    in_sum += c * arr[b];
    arr[c] += arr[b];
    arr[b] = 0;
    cout << in_sum << endl;
  }
  return 0;
}
