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