#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a, b, c, d, m, n, maxi = 0, f = 0, mini = 1001001001, sum = 0;
  string str;
  cin >> n;
  vector<long long> v(n);
  for (long long i = (long long)(0); i < (long long)(n); i++) cin >> v[i];
  long long q;
  map<long long, long long> ma;
  vector<pair<long long, long long>> p;
  long long num = 1;
  for (long long i = 0; i < n; i++) {
    ma[v[i]]++;
    sum += v[i];
  }
  cin >> q;
  for (long long _ = (long long)(0); _ < (long long)(q); _++) {
    long long be, to;
    cin >> be >> to;
    sum -= ma[be] * be;
    ma[to] = ma[to] + ma[be];
    sum += ma[be] * to;
    cout << sum << endl;
  }
  return 0;
}
