#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  long long q;
  vector<long long> s;
  long long a[100001];
  for (int i = 0; i < 100001; i++) a[i] = 0;
  cin >> n;
  s.push_back(0);
  for (long long i = 0; i < n; i++) {
    long long aa;
    cin >> aa;
    s[0] += aa;
    a[aa]++;
  }
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    long long cnt = a[b];
    s[i] += cnt * (c - b);
    a[c] += cnt;
    s.push_back(s[i]);
  }
  for (int i = 0; i < q; i++) {
    cout << s[i] << endl;
  }
}
