#include <bits/stdc++.h>
unsigned long long DENOM = 1000000000LL + 7LL;
using namespace std;
int main() {
  unsigned long long n;
  cin >> n;
  map<unsigned long long, unsigned long long> a;
  unsigned long long s;
  for (int i = 0; i < n; ++i) {
    unsigned long long at;
    cin >> at;
    a[at] += 1;
    s += at;
  }
  unsigned long long q;
  cin >> q;
  vector<pair<unsigned long long, unsigned long long> > bc;
  for (int i = 0; i < q; ++i) {
    unsigned long long b, c;
    cin >> b >> c;
    bc.push_back(make_pair(b, c));
  }
  for (int i = 0; i < q; ++i) {
    unsigned long long b, c;
    b = bc[i].first;
    c = bc[i].second;
    s += (c - b) * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << s << endl;
  }
}
