#include <bits/stdc++.h>
using namespace std;
int main() {
  int len;
  cin >> len;
  int sum = 0;
  map<int, int> numCount;
  for (int i = 0; i < len; i++) {
    int a;
    cin >> a;
    sum += a;
    numCount[a] += 1;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int amount = numCount[b];
    sum += amount * (c - b);
    cout << sum << endl;
    numCount[c] += amount;
    numCount[b] = 0;
  }
}
