#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, q;
  cin >> n;
  int tmp;
  int a[100001] = {};
  int sum = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> tmp;
    sum += tmp;
    a[tmp]++;
  }
  cin >> q;
  int b, c;
  for (int i = 0; i < (q); ++i) {
    cin >> b >> c;
    if (a[b] > 0) {
      sum += (c - b) * a[b];
      a[c] += a[b];
      a[b] = 0;
    }
    cout << sum << endl;
  }
}
