#include<iostream>

using namespace std;

int main() {

  		int n;
  		cin >> n;
		int ar[n] = {};
		
		for(int i=0; i<n; i++) cin >> ar[i];
		
		int q;
  		cin >> q;
		
		for(int i=0; i<q; i++) {
			int b;
          	cin >> b;
			int c;
          	cin >> c;
          		int sum = 0;
				for(int j=0; j<n; j++) {
					if(ar[j] == b)
						ar[j] = c;
                  	sum += ar[j];
                }
				cout << sum << " ";
		}
  
  return 0;
}