#include <iostream>

#include <string>

#include <math.h>

#include <algorithm>

#include <iomanip>

#include <vector>

#include <set>

#include <list>

#include <queue>

#include <stack>

#include <map>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS

#define Abs                           \

	ios_base::sync_with_stdio(false); \	cout.tie(NULL);                   \

	cin.tie(NULL);

#define FOR(i, b, a) for (ll i = b; i < a; i++)

#define FOR1(i, b, a) for (ll i = b; i <= a; i++)

#define FORd(i, b, a) for (ll i = (a)-1; i >= b; i--)

const double PI = acos(-1);

#define all(v) ((v).begin()), ((v).end())

#define allr(v) ((v).rbegin()), ((v).rend())

#define iq(v)   v.resize(unique(v.begin(), v.end()) - v.begin())

#define endl "\n"

#define sz(v) ((ll)((v).size()))

#define fx(n)           fixed << setprecision(n)

typedef unsigned long long ull;

typedef long long ll;

typedef vector<ll> vi;

typedef pair<ll, ll> pii;

const int mod = 1e9 + 7;

int main()

{

	Abs;

	ll n, q, s = 0;

	cin >> n;

	map<ll, ll> m;

	FOR(i, 0, n)

	{

		ll x;

		cin >> x;

		s += x;

		m[x]++;

	}

	cin >> q;

	while (q--)

	{

		ll b, c;

		cin >> b >> c;

		s -= (b * m[b]);

		s += (m[b] * c);

		if (m.find(c) == m.end())

			m[c] = m[b];

		else

			m[c] += m[b];

		m.erase(b);

		cout << s << endl;

	}

}