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