#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double PI = acos(-1);
const long long MOD = 1000000007;
const long long FMOD = 998244353;
const long double eps = 1e-9;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
signed main() {
  long long n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  map<long long, long long> mp1;
  for (long long i = 0; i < n; i++) cin >> a[i], sum += a[i], mp1[a[i]]++;
  long long q;
  cin >> q;
  while (q--) {
    long long a, b;
    cin >> a >> b;
    sum -= mp1[a] * a;
    sum += mp1[a] * b;
    mp1[b] += mp1[a];
    cout << sum << endl;
  }
}
