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