#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, x;
  cin >> n;
  int arr[100005] = {0};
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    arr[x]++;
    sum += x;
  }
  int Q;
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    int u, v;
    cin >> u >> v;
    sum -= arr[u] * u;
    sum += arr[u] * v;
    cout << sum << endl;
    arr[v] += arr[u];
    arr[u] = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
