#include <bits/stdc++.h>
using namespace std;
using VVI = vector<vector<int>>;
using VI = vector<int>;
const static string el = "\n";
int main() {
  int n;
  cin >> n;
  unsigned long long total = 0;
  VI a(n);
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a[i] = tmp;
    total += tmp;
  }
  sort(a.begin(), a.end());
  int q;
  cin >> q;
  int replace_count = 0;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    for (int k = 0; k < n; k++) {
      if (a[k] == b) {
        a[k] = c;
        replace_count++;
      } else if (a[k] < b) {
        continue;
      } else {
        break;
      }
    }
    if (replace_count > 0) {
      int df = c - b;
      total += df * replace_count;
      cout << total << el;
      replace_count = 0;
      sort(a.begin(), a.end());
    } else {
      cout << total << el;
    }
  }
  return 0;
}
