#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long MOD = 1000000000 + 7;
int main() {
  int n;
  cin >> n;
  map<int, int> a;
  int tmp;
  for (int i = 0; i < (int)(n); i++) {
    cin >> tmp;
    a[tmp]++;
  }
  int q;
  cin >> q;
  int b, c;
  unsigned long long cnt = 0;
  pair<int, int> p;
  for (auto itr = a.begin(); itr != a.end(); itr++) {
    p = *itr;
    cnt += p.first * p.second;
  }
  for (int i = 0; i < (int)(q); i++) {
    cin >> b >> c;
    tmp = a[b];
    a[c] += tmp;
    a[b] -= tmp;
    cnt += c * tmp;
    cnt -= b * tmp;
    cout << cnt << endl;
  }
  return 0;
}
