#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using LL = long long;
using P = pair<int,int>;


int main(){
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	int q;cin >> q;
	rep(i,q){
		int b, c;
		cin >> b >> c;
		int ans = 0;
		rep(j,n){
			if(a[j] == b) a[j] = c;
			ans += a[j];
		}
		cout << ans << endl;
	}
     return 0;

}


