#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n;
  int has[100001] = {0};
  vector<long long> a(n, 0);
  long long sum = 0;
  for (int i = 0; i < (n); ++i) cin >> a[i];
  for (int i = 0; i < (n); ++i) {
    sum += a[i];
    has[a[i]]++;
  }
  cin >> q;
  for (int _ = 0; _ < (q); ++_) {
    int b, c;
    cin >> b >> c;
    int cntb = has[b];
    sum = sum - cntb * b + cntb * c;
    has[b] = 0;
    has[c] += cntb;
    cout << sum << endl;
  }
  return 0;
}
