#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int arr[n];
  unordered_map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]]++;
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += arr[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    int temp = mp[l];
    mp[l] = 0;
    mp[r] += temp;
    sum = sum - (l * temp) + (r * temp);
    cout << sum << "\n";
  }
}
int main() {
  int y;
  y = 1;
  while (y--) {
    solve();
  }
}
