#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, sum = 0;
  cin >> n;
  vector<bool> arr(100000 + 1, false);
  vector<int> fr(100000 + 1, 0);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    arr[a] = true;
    fr[a]++;
    sum += a;
  }
  cin >> q;
  vector<int> res;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (arr[b]) {
      sum += (c - b) * fr[b];
      arr[c] = true;
      fr[c] += fr[b];
      fr[b] = 0;
    }
    res.push_back(sum);
  }
  for (int x : res) {
    cout << x << endl;
  }
}
