#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, sum = 0;
  cin >> n;
  map<int, ll> a;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    int x = a[b];
    sum = sum + (c - b) * x;
    a[c] += a[b];
    a[b] = 0;
    cout << sum << "\n";
  }
  return 0;
}
