#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 5;
int cnt[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> A;
  long long int sum = 0LL;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum += x;
    A.push_back(x);
    cnt[x]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    int x = cnt[b];
    int res = cnt[a];
    sum -= res * a;
    cnt[b] += res;
    sum += (1LL * (cnt[b] - x) * b);
    cout << sum << "\n";
  }
  return 0;
}
