#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n;
  cin >> n;
  long long arr[n + 1];
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    long long sum = 0;
    for (long long i = 1; i <= n; i++) {
      if (arr[i] == b) {
        arr[i] *= c;
        c = arr[i] / b;
        arr[i] /= b;
      }
      sum += arr[i];
    }
    cout << sum << "\n";
  }
}
