#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long tmp = 0;
  vector<int> a(100010, 0);
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    a[d - 1]++;
    tmp += d;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int countb = a[b - 1];
    int countc = a[c - 1];
    tmp = tmp - countb * b + countb * c;
    cout << tmp << endl;
    a[c - 1] += a[b - 1];
    a[b - 1] = 0;
  }
}
