///   BISMILLAHIR RAHMANIR RAHEEM
///   ALLAH IS WATCHING ME
///   ALLAH save us from COVID-19.Amin.

///   █▀█─█──█──█▀█─█─█
///   █▄█─█──█──█▄█─█▄█
///   █─█─█▄─█▄─█─█─█─█

///   كُلُّ نَفْسٍ ذَآئِقَةُ الْمَوْت
///   Every soul shall taste death.



#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

///  order_of_key return number of elements less than x.
///  find_by_order return index.

using namespace std;
using namespace __gnu_pbds;


#define MOHAMMAD  ios::sync_with_stdio(0);cin.tie(0);
#define all(x)    (x).begin(), (x).end()
#define AE        cout << fixed << setprecision(10);

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[]= {1,-1,0,0}; // 4-direction...........
int dy4[]= {0,0,1,-1};

typedef tree< int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

//***********************************************  The END **********************************************************************************************************************************




int main()
{

     MOHAMMAD
  int n , sum = 0 , x;
  cin >> n;

  map < long long , long long > oc;

  for ( int i = 0 ; i<n ; ++i ){
       cin >> x;
       sum+=x;
       oc[x]++;
  }

  long long q , b ,c;
  cin >> q;
  while ( q-- ){
        cin >> b >> c;
        long long times = oc[b];
        sum-=(b*times);
        oc[c]+= oc[b];
        //oc[b] = 0;
        sum+=(c*oc[b]);
        oc[b] = 0;
        cout << sum << "\n";
  }

}

/*





  Alhamdulillah
*/

