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