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