#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
int arr[100001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  long sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    arr[tmp]++;
    sum += tmp;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int a, b;
    cin >> a >> b;
    sum -= arr[a] * a;
    sum += arr[a] * b;
    arr[b] += arr[a];
    arr[a] = 0;
    cout << sum << endl;
  }
}
