#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int all[100010];
  for (int i = 0; i < 10010; i++) {
    all[i] = 0;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    ans += temp;
    all[temp]++;
  }
  int q;
  cin >> q;
  int b[q], c[q];
  for (int i = 0; i < q; i++) {
    int temp1, temp2;
    cin >> temp1 >> temp2;
    b[i] = temp1;
    c[i] = temp2;
    int count = all[temp1];
    ans = ans + (temp2 - temp1) * count;
    all[temp2] += all[temp1];
    all[temp1] = 0;
    cout << ans << endl;
  }
}
