#include <bits/stdc++.h>

#define int long long
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

const unsigned int M = 1e9 + 7;

int32_t main() {
	fastio;

	int n;
	cin >> n;
	int sum = 0, freq[1e5 + 1];
	while(n--) {
		int x;
		cin >> x;
		sum += x;
		++freq[x];
	}
	int q;
	cin >> q;
	while(q--) {
		int b, c;
		cin >> b >> c;
		sum += c * freq[c], sum -= b;
		cout << sum << '\n';
	}

	return 0;
}

/*
Pre-computing sum gives 1+2+3+4
* Now, to remove 1 and add 2 -> (1+2+3+4) - (1) + (2)
* Similarly to remove 3 and add 2 now, current sum - 3 + 2
* And so on
*/
