#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  cin >> q;
  vector<pair<int, int>> bc(q);
  for (int i = 0; i < (q); i++) cin >> bc[i].first >> bc[i].second;
  vector<long long> qty(100001);
  vector<long long> index;
  for (int i = 0; i < (n); i++) {
    qty[a[i]]++;
    index.push_back(a[i]);
  }
  sort(index.begin(), index.end());
  index.erase(unique(index.begin(), index.end()), index.end());
  for (int i = 0; i < (q); i++) {
    int before = bc[i].first;
    int after = bc[i].second;
    qty[after] += qty[before];
    qty[before] = 0;
    vector<long long>::iterator itr = find(index.begin(), index.end(), after);
    if (itr == index.end()) index.push_back(after);
    itr = find(index.begin(), index.end(), before);
    if (itr != index.end()) index.erase(itr);
    long long sum = 0;
    for (long long j : index) {
      sum += qty[j] * j;
    }
    cout << sum << endl;
  }
}
