#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  ll sum = 0;
  vector<int> a(100001, 0);
  for (int i = (0); i < (int)(n); i += 1) {
    int num;
    cin >> num;
    sum += num;
    a[num]++;
  }
  int q;
  cin >> q;
  for (int i = (0); i < (int)(q); i += 1) {
    int b, c;
    cin >> b >> c;
    a[c] += a[b];
    sum -= a[b] * b;
    sum += a[b] * c;
    a[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
