#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void solve() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(100001);
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    a[m]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int y = a[b];
    a[b] = 0;
    a[c] += y;
    ll sum = 0;
    for (int i = 1; i < 100001; i++) {
      if (a[i] != 0) {
        sum += i * a[i];
      }
    }
    cout << sum << endl;
  }
  return 0;
}
