#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void print_map_total(map<ll, ll> a) {
  ll total = 0;
  for (auto i = a.begin(); i != a.end(); ++i) {
    total += (i->first) * (i->second);
  }
  cout << total << endl;
}
int main() {
  int n;
  cin >> n;
  map<ll, ll> a;
  int temp;
  for (int i = 0; i < (int)(n); i++) {
    cin >> temp;
    a[temp]++;
  }
  int q;
  cin >> q;
  vector<ll> b(q), c(q);
  for (int i = 0; i < (int)(q); i++) {
    cin >> b[i];
    cin >> c[i];
  }
  int henka = 0;
  for (int i = 0; i < (int)(q); i++) {
    henka = a[b[i]];
    a[b[i]] = 0;
    a[c[i]] += henka;
    print_map_total(a);
  }
}
