#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 5;
int n, a[N], cnt[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++cnt[a[i]];
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    sum -= l * cnt[l];
    sum += r * cnt[l];
    cnt[r] += cnt[l];
    cnt[l] = 0;
    cout << sum << "\n";
  }
}
