#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int fx[] = {+1, -1, +0, +0};
const int fy[] = {+0, +0, +1, -1};
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
const long long int N = 1e5 + 10;
long long int a[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  t = 1;
  while (t--) {
    unsigned long long int n;
    cin >> n;
    map<unsigned long long int, unsigned long long int> mps;
    unsigned long long int sum = 0;
    for (long long int i = 1; i <= n; i++) {
      long long int x;
      scanf("%llu", &x);
      a[x]++;
    }
    for (long long int i = 1; i <= n; i++) {
      long long int x = a[i];
      sum += x * i;
      if (x) mps[i] = x;
    }
    long long int q;
    cin >> q;
    while (q--) {
      unsigned long long int b, c;
      scanf("%llu %llu", &b, &c);
      unsigned long long int p = mps[b];
      mps.erase(b);
      unsigned long long int q = mps[c];
      mps.erase(c);
      mps.insert({c, p + q});
      sum -= p * b;
      sum += p * c;
      {
        string _s = "p";
        replace(_s.begin(), _s.end(), ',', ' ');
        stringstream _ss(_s);
        istream_iterator<string> _it(_ss);
        err(_it, p);
      };
      printf("%llu\n", sum);
    }
  }
  return 0;
}
