#include <bits/stdc++.h>
using namespace std;
const int MOD = 1E9 + 7;
const int N = 1E5;
vector<int> cnt(N + 5, 0);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long sum = 0;
  vector<long long> a(n);
  for (int i = 0; i <= n - 1; i++) {
    cin >> a[i];
    sum += a[i];
    ++cnt[a[i]];
  }
  int q;
  cin >> q;
  for (int qq = 1; qq <= q; qq++) {
    long long ai, bi;
    cin >> ai >> bi;
    sum = sum + (bi - ai) * cnt[ai];
    cnt[ai] = 0;
    cnt[bi] += ai;
    cout << sum << endl;
  }
}
