#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  long long int sum = 0;
  int cnt[100005] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    cnt[a[i]]++;
  }
  int q;
  cin >> q;
  long long int sum1 = sum;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int va = cnt[b];
    if (va == 0) {
      cout << sum1 << endl;
    } else {
      sum1 -= (va * b);
      sum1 += (va * c);
      cnt[c] += va;
      cnt[b] = 0;
      cout << sum1 << endl;
    }
  }
}
