#include <bits/stdc++.h>
using namespace std;
const long long INFL = 1LL << 60;
const long long MOD = 1000000007;
const int INF = INT_MAX;
const int MAX = 300000;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return (a * b) / GCD(a, b); }
const long long M = 26;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> cnt(100010, 0);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    cnt[a]++;
    ans += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    ans -= b * cnt[b];
    ans += c * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << ans << endl;
  }
}
