#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
int a[100000];
int n;
long long sum = 0;
void change() {
  int l, m;
  scanf("%d%d", &l, &m);
  for (int j = 0; j < n; ++j) {
    if (a[j] == l) a[j] = m;
  }
}
void solve() {
  for (int j = 0; j < n; ++j) sum += a[j];
  printf("%lld\n", sum);
  sum = 0;
}
signed main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; ++i) {
    change();
    solve();
  }
  return 0;
}
