#include <bits/stdc++.h>
using namespace std;


int main()
{  
  #ifndef ONLINE_JUDGE
	 freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  #endif

   long long n;
   cin>>n;
   map<long long, long long> m;
   long long a[n];
   long long sum=0;
   for(int i=0; i<n; i++)
   	 {cin>>a[i]; m[a[i]]++; sum+=a[i];}

   long long k;
   cin>>k;

   while(k--)
   { long long l,r;
   	 cin>>l>>r;

   	 sum-=l*m[l];
   	 sum+= r*m[l];
   	 m[r]+= m[l];
   	 m[l]=0;

   	 cout<<sum<<endl;
      


   }