#include <bits/stdc++.h>
#include <stdint.h>
#define mod 1000000007
#define ull unsigned ll
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pi 3.1415926535897932
#define nui 100
using namespace std;

/*-------------------------------------------------------------*/
//for (a*b)%mod

uint64_t mulmod(uint64_t a, uint64_t b, uint64_t m)
{
	long double x;
	uint64_t c;
	int64_t r;
	if (a >= m) a %= m;
	if (b >= m) b %= m;
	x = a;
	c = x * b / m;
	r = (int64_t)(a * b - c * m) % (int64_t)m;
	return r < 0 ? r + m : r;
}

/*-------------------------------------------------------------*/

ull binpowmod(ull a, ull b, ull m)
{
	ull res = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			res = ((res % m) * (a % m)) % m;
		}
		a = ((a % m) * (a % m)) % m;
		b >>= 1;
	}
	return res;
}

/*-------------------------------------------------------------*/

ll countsetbits(ll n)
{
	ll count = 0;
	while (n > 0)
	{
		n = n & (n - 1);
		count++;
	}
	return count;
}

/*-------------------------------------------------------------*/
ll binpow(ll a, ll b)
{
	ll res = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			res *= a;
		}
		a *= a;
		b >>= 1;
	}
	return res;
}
/*-------------------------------------------------------------*/
ll binarysearch(ll l, ll r, ll a[], ll x)
{
	while (l <= r)
	{
		ll mid = l + ((r - l) / 2);

		if (a[mid] == x )
		{
			return mid ;
		}
		if (a[mid] < x)
		{
			l = mid + 1;
		}
		else
		{
			r = mid - 1;
		}
	}
	return -1;
}

void printNcR(ll n, ll r)
{

	ll p = 1, k = 1;

	if (n - r < r)
		r = n - r;

	if (r != 0)
	{
		while (r)
		{
			p *= n;
			k *= r;

			ll m = __gcd(p, k);
			p /= m;
			k /= m;

			n--;
			r--;
		}
	}

	else
		p = 1;

	cout << p << "\n";
}
/*--------------------------------------------------------------*/
//Adjacency list

vector<ll>adj[100005];

ll vis[100005];  //how many i-th nodes have been visited
void dfs(ll node)
{
	vis[node] = 1;
	for (ll child : adj[node])
	{
		if (!vis[child])
		{
			dfs(child);
		}
	}
}

/*--------------------------------------------------------------*/
/* Upper bound of x gives numbers less than or equal to x */

ll countdig(ll n)
{
	ll count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}

/*-------------------------------------------------------------*/

bool primech(ll n)
{
	// Corner cases
	if (n <= 1)  return false;
	if (n <= 3)  return true;

	// This is checked so that we can skip
	// middle five numbers in below loop
	if (n % 2 == 0 || n % 3 == 0) return false;

	for (int i = 5; i * i <= n; i = i + 6)
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	return true;
}

/*----------------------------------------------------------------*/

bool sortbysec(const pair<char, char> &a, const pair<char, char> &b)
{
	return (a.second < b.second);
}

// Sort first part in descending
bool sortinrev(const pair<char, char> &a, const pair<char, char> &b)
{
	return (a.first > b.first);
}

/*-------------------------------------------------------------*/

clock_t time_p = clock();
void TLE()
{
	time_p = clock() - time_p;
	cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

/*-------------------------------------------------------------*/

/*vector<ll>v;
bool prime[10000001]
void seive()
{
	memset(prime,1,sizeof(prime));
	for(ll i=2;i*i<=10000001;i++)
	{
		if(prime[i]==1)
		{
			for(ll j=1;j<=i*i;j+=i)
			{
				prime[j]=0;
			}
		}
	}

} */
/*
ll arr[nui][nui], I[nui][nui];
void mulmat(ll A[][nui], ll B[][nui], ll m)
{
	ll res[m][m];
	for (ll i = 0; i < m; i++)
	{
		for (ll j = 0; j < m; j++)
		{
			res[i][j] = 0;
			for (ll k = 0; k < m; k++)
			{
				res[i][j] += ((A[i][k]) * (B[k][j]));
			}

		}
	}
	for (ll i = 0; i < m; i++)
	{
		for (ll j = 0; j < m; j++)
		{
			A[i][j] = res[i][j];
		}
	}
}
ll calpowmat(ll A[][nui], ll m, ll n)
{
	for (ll i = 0; i < m; i++)
	{
		for (ll j = 0; j < m; j++)
		{
			if (i == j)
			{
				I[i][j] = 1;
			}
			else
			{
				I[i][j] = 0;
			}
		}
	}
	while (n)
	{
		if (n % 2)
		{
			mulmat(I, A, m), n--;
		}
		else
		{
			mulmat(A, A, m), n /= 2;
		}
	}
	for (ll i = 0; i < m; i++)
	{
		for (ll j = 0; j < m; j++)
		{
			A[i][j] = I[i][j];
		}
	}
	return ( A[0][0] +  A[1][0]);


}*/



/*-------------------------------------------------------------*/
bool checkerpow(ll n)
{
	ll count = 0;
	while (n > 0)
	{
		n = n & (n - 1);
		count++;
	}
	if (count == 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

int main()
{


	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	ll n;
	cin >> n;
	ll a[n];
	map<ll, ll>m;
	ull sum = 0;
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];
		m[a[i]]++;
		sum += a[i];
	}
	ll q, x, y;
	cin >> q;
	while (q--)
	{
		cin >> x >> y;
		cout << sum - m[x]*x + m[x]*y << "\n";
		sum = sum - m[x] * x + m[x] * y;
		m[y] += m[x];
		m[x] = 0;
	}


	return 0;
}



Measured memory_bytes: 12624