#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const int MAX = 500000;
const int inf = 1000000007;
const long long mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
long long n, q, a[100005], b[100005], c[100005], ans[100005];
long long cnt[100005];
int main() {
  cin >> n;
  for (int i = (int)(0); i < (int)(n); ++i) {
    cin >> a[i];
    cnt[a[i]]++;
    ans[0] += a[i];
  }
  cin >> q;
  for (int i = (int)(1); i < (int)(q + 1); ++i) {
    cin >> b[i] >> c[i];
    ans[i] = ans[i - 1] + cnt[b[i]] * (c[i] - b[i]);
    cnt[c[i]] += cnt[b[i]];
    cnt[b[i]] == 0;
  }
  for (int i = (int)(1); i < (int)(q + 1); ++i) cout << ans[i] << endl;
  return 0;
}
