using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		long[]A = new long[N];
		int[]E = new int[100001];
		string[] str = Console.ReadLine().Split();
		long sum = 0;
		for(var i=0;i<N;i++){
			A[i] = long.Parse(str[i]);
			E[(int)A[i]-1]++;
			sum += A[i];
		}
		int Q = int.Parse(Console.ReadLine());
		for(var i=0;i<Q;i++){
			string[] str2 = Console.ReadLine().Split();
			int B = int.Parse(str2[0]);
			int C = int.Parse(str2[1]);
			sum -= E[B-1]*B;
			sum += E[B-1]*C;
			E[C-1] += E[B-1];
			E[B-1] = 0;
			Console.WriteLine(sum);
		}
	}
}