#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
int main() {
  int n;
  cin >> n;
  ll sum = 0;
  map<int, int> a;
  for (int i = 0; i < (n); i++) {
    int aa;
    cin >> aa;
    a[aa]++;
    sum += aa;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    if (a[b] == 0)
      cout << sum << endl;
    else {
      sum -= b * a[b];
      sum += c * a[b];
      cout << sum << endl;
      a[c] = a[b] + a[c];
      a[b] = 0;
    }
  }
  return 0;
}
