#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
int tab[11];
void base26(ll nombre) {
  int base = 26;
  int i = 10;
  while (nombre) {
    tab[i] = nombre % base;
    if (tab[i] == 0) {
      tab[i] = 26;
      nombre -= 26;
    }
    nombre /= base;
    i--;
  }
}
int occurence[100005];
int main() {
  int n;
  cin >> n;
  int num;
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> num;
    occurence[num]++;
    sum += num;
  }
  int operation;
  cin >> operation;
  for (int i = 0; i < operation; ++i) {
    int a, b;
    cin >> a >> b;
    sum -= a * occurence[a];
    occurence[b] += occurence[a];
    sum += b * occurence[a];
    occurence[a] = 0;
    cout << sum << endl;
  }
  return 0;
}
