#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int i, j, k, x, y, z, n, a, b, c, c1 = 0, c2 = 0, flag = 0, sum = 0;
  cin >> n;
  long long int arr[n];
  for (i = 0; i < n; i++) cin >> arr[i];
  cin >> k;
  while (k--) {
    sum = 0;
    cin >> a >> b;
    for (i = 0; i < n; i++) {
      if (arr[i] == a) {
        sum = sum + b;
        arr[i] = b;
      } else
        sum = sum + arr[i];
    }
    cout << sum << "\n";
  }
}
