#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m[100001], a, b;
  cin >> n;
  memset(m, 0, sizeof(100001));
  long long arr[n];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    m[arr[i]]++;
    sum += arr[i];
  }
  int q;
  cin >> q;
  while (q--) {
    cin >> a >> b;
    long long cntr = m[a];
    sum -= cntr * a;
    sum += cntr * b;
    m[a] -= cntr;
    m[b] += cntr;
    cout << sum << endl;
  }
}
