#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
const long long INF = 0xFFFFFFFFFFFFFFFL;
;
const long long N = 1e9 + 7;
void swap1(long long a, long long b) {
  long long temp;
  temp = a;
  a = b;
  b = temp;
}
void solve() {
  long long n, q;
  cin >> n;
  vector<long long> a;
  for (long long i = 0; i < n; i++) {
    long long item;
    cin >> item;
    a.push_back(item);
  };
  long long sum = 0;
  long long count[1000002];
  for (long long i = 0; i < 1000002; i++) count[i] = 0;
  cin >> q;
  for (long long i = 0; i < n; i++) {
    count[a[i]]++;
    sum = sum + a[i];
  }
  long long b, c;
  for (long long i = 0; i < q; i++) {
    cin >> b >> c;
    sum = sum - b * count[b] + c * count[b];
    cout << sum << "\n";
    count[c] = count[c] + count[b];
  }
}
int32_t main(int32_t argc, char **argv) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) solve();
  cerr << "\n"
       << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
