#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q, sum = 0;
  cin >> n;
  vector<int> A(n);
  unordered_map<int, int> freq;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    freq[A[i]]++;
    sum += A[i];
  }
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    sum -= (a - b) * freq[a];
    freq[b] += freq[a];
    freq[a] = 0;
    cout << sum << endl;
  }
}
