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