#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  vector<int> flag(100001, 0);
  long long sum = 0;
  for (int i = 0; i < n; i += 1) {
    cin >> arr[i];
    flag[arr[i]]++;
    sum += arr[i];
  }
  int q;
  cin >> q;
  int b, c;
  for (int i = 0; i < q; i += 1) {
    cin >> b >> c;
    sum -= flag[b] * b;
    sum += flag[b] * c;
    flag[c] += flag[b];
    flag[b] = 0;
    cout << sum << endl;
  }
}
