#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
using Graph = vector<vector<long long>>;
using ll = long long;
signed main() {
  long long n;
  cin >> n;
  vector<long long> A(20000000, 0);
  long long a[n];
  for (long long i = 0; i < n; i++) {
    long long ai;
    cin >> ai;
    a[i] = ai;
    A[ai] += 1;
  }
  long long q;
  cin >> q;
  vector<long long> scores;
  long long result = accumulate(a, a + n, 0);
  for (long long i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    result = result + (c - b) * A[b];
    A[c] += A[b];
    A[b] = 0;
    scores.push_back(result);
  }
  for (long long i = 0; i < q; i++) {
    cout << scores[i] << endl;
  }
}
