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