#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = 1e6;
long long arr[N];
long long sum = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, q;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum += x;
    arr[x]++;
  }
  cin >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    sum = sum - (x * arr[x]) + y * arr[x];
    arr[y] += arr[x];
    cout << sum << '\n';
  }
  return 0;
}
