#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const double PI = atan(1.0) * 4;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
const int N = 1e5 + 50;
int cnt[N];
long long power(long long a, long long e) {
  long long res = 1LL;
  while (e > 0) {
    if (e % 2 == 1) res = res * a % MOD;
    a = a * a % MOD;
    e /= 2;
  }
  return res;
}
vector<int> complement(const vector<int> &vec) {
  int n = vec.size();
  vector<bool> occur(n + 1, true);
  vector<int> ans;
  for (int i = 0; i < (int)vec.size(); i++) {
    occur[vec[i]] = false;
  }
  for (int i = 1; i <= n; i++) {
    if (occur[i]) ans.push_back(i);
  }
  return ans;
}
long long intlog(double base, double x) {
  return (long long)(log(x) / log(base));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    ++cnt[b];
    ans += b;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    ans -= b * cnt[b];
    ans -= c * cnt[c];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    ans += b * cnt[b];
    ans += c * cnt[c];
    cout << ans << "\n";
  }
  return 0;
}
