#include <bits/stdc++.h>
using namespace std;
string digit = "0123456789";
string small = "abcdefghijklmnopqrstuvwxyz";
string capital = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {1, -1, 0, 0};
int dy4[] = {0, 0, 1, -1};
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  int arr[n];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]]++;
    sum += arr[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    sum -= mp[a] * a;
    sum += mp[a] * b;
    cout << sum << "\n";
    mp[b] += mp[a];
    mp[a] = 0;
  }
}
