#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  int a[100000 + 5];
  int b, c;
  int nums[100000 + 5];
  int sum = 0;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    nums[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    sum += (c - b) * nums[b];
    nums[c] += nums[b];
    nums[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
