#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ template.cpp -o template.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0  |  \
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;
#define MAX 50 







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 


void countFreq(int arr[], long long  int n, vector< pair <long long int, long long int> > &v) 
{ 
    // Mark all array elements as not visited 
    vector<bool> visited(n, false); 
  
    // Traverse through array elements and 
    // count frequencies 
    for (int i = 0; i < n; i++) { 
  
        // Skip this element if already processed 
        if (visited[i] == true) 
            continue; 
  
        // Count frequency 
        int count = 1; 
        for (int j = i + 1; j < n; j++) { 
            if (arr[i] == arr[j]) { 
                visited[j] = true; 
                count++; 
            } 
        } 
        vect.push_back( make_pair(arr[i],count) );
    } 
} 






int main()
{
	long long int k,n,i,sum=0,q,b,c,k,sum1;
	vector< pair <long long int, long long int> > v;
	cin>>n;
	int ar[n];
	for(i=0;i<n;i++)
	{
		cin>>ar[i];
		sum+=ar[i];
	}
	countFreq(ar,n.v);

	cin>>q;
	while(q--)
	{
		cin>>b>>c;
		k=0;
		for(i=0;i<n;i++)
	    {
	    	if(v[i].first==b)
	    	{
	    		k=1;
	    		v[i].first=c;
	    		break;
	    	}
	    }
	    if(k==1)
	    {
	    	sum=sum+(c-b)*v[i].second;
	    	cout<<sum;

	    }


	}


	

	cout<<sum;


	return 0;
}