#include <algorithm>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <bits/stdc++.h>

int main() {
  	int N;
  	int K;
	cin >> N;
  	vector<int> input(N);
  	unordered_map<int, int> hash;
  	int sum = 0;
  	for(int i = 0; i < N; i++) {
      cin >> input[i];
      hash[input[i]]++;
      sum += input[i];
    }
  	cin >> K;
    int orig, upd;
    for(int i = 0; i < K; i++){
      cin >> orig >> upd;
      int num = hash[orig];
      int diff = upd - orig;
      hash.erase(orig);
      hash[upd] += num;
      sum += diff * num;
      cout << sum << endl;
    }
}