#include <bits/stdc++.h>
#include<string.h>
#include <algorithm>
#include<math.h>
#include<vector>
#include <queue>
#include <deque> 
#define ll long long
#define M 1000000007 
#define MM 998244353
using namespace std;
 
int main()
{
    long long int n, sum = 0;
    cin >> n;

    long long int a[n] = {0}, x;

    for (long long int i = 0; i < n; i++)
    {
   		cin >> x;
   		a[x-1]++;
   		sum = sum + x;
    }

    // for (long long int i = 0; i < n; i++)
    // {
   	// 	cout << a[i] << " ";
    // }

    long long int q;
    cin >> q;

    long long int b[q], c[q];

    for (long long int i = 0; i < q; i++)
    {
    	cin >> b[i] >> c[i];
    }

    for (long long int i = 0; i < q; i++)
    {
    	sum = sum + (c[i] - b[i])*(a[b[i] - 1]);
    	cout << sum << endl;
    	a[c[i] - 1] = a[c[i] - 1] + a[b[i] - 1];
    	a[b[i] - 1] = 0;
    }

    return 0;
}