#include <bits/stdc++.h>
#include <ext/rope>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
 
#define file ""
 
#define all(x) x.begin(), x.end()
 
#define sc second
#define fr first
 
#define pb push_back
#define mp make_pair
 
#define pss pair<line*, line*>
 
using namespace std;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
                                 
const ll inf = 1e18;
const int MOD = 1e9 + 7;
 
const int dx[] = {-1, +1, -2, +2, -2, +2, -1, +1};
const int dy[] = {-2, -2, -1, -1, +1, +1, +2, +2};
 
int const N = 3e5 + 5;
int const M = 1e8	;

int main() {                 
#ifdef Mask                                                         
  freopen(".in", 	"r", stdin);
  freopen(".out", "w", stdout);  
#endif
	ios_base :: sync_with_stdio(false);               
  cin.tie(nullptr);
  srand(time(nullptr));	
  int n;
  cin >> n;
  int a[n + 1];
  map<int, int> cnt;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
  	cin >> a[i];
  	cnt[a[i]]++;
  	sum += a[i];
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
   	int a, b;
   	cin >> a >> b;
   	sum -= cnt[a] * a;
   	cnt[b] += cnt[a];
   	sum += cnt[a] * b;
   	cnt[a] = 0;
   	cout << sum << endl;
  }
	return 0;                    
 
}