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