#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
const long long M = 1e5 + 5;
int n, q;
int a[M], b[M], c[M];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> q;
  for (int i = 1; i <= q; i++) cin >> b[i] >> c[i];
  for (int i = 1; i <= q; i++) {
    long long ans = 0;
    for (int j = 1; j <= q; j++)
      if (a[j] == b[i]) a[j] = c[i];
    for (int k = 1; k <= n; k++) ans += a[k];
    cout << ans << endl;
  }
  return 0;
}
