#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int sum = 0;
  long long int a[n];
  long long int hash[100001] = {0};
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    hash[a[i]]++;
  }
  long long int m;
  cin >> m;
  while (m--) {
    long long int u, v;
    cin >> u >> v;
    hash[v] += hash[u];
    sum += v * hash[u] - u * hash[u];
    cout << sum << "\n";
  }
}
