#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[100010] = {}, b, q, c, n;
  long long ans;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    ans = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] == b) {
        a[j] = c;
      }
      ans += a[j];
    }
    cout << ans << "\n";
  }
  return (0);
}
