    using System;
    using System.Collections.Generic;
	using System.Linq;
    class Program
    {
      static int n;
      static int[] a = new int[100001];
      static int sum;
      static void Main()
      {
        n = int.Parse(Console.ReadLine());
        var line = Console.ReadLine();
        var _line = line.Split(" ");
        for (int i = 0; i < n; i++)
        {
          int num = int.Parse(_line[i]);
          sum += num;
          a[num]++;
        }
        int q = int.Parse(Console.ReadLine());
        for (int i = 0; i < q; i++)
        {
          line = Console.ReadLine();
          _line = line.Split(" ");
          int b = int.Parse(_line[0]);
          int c = int.Parse(_line[1]);
          sum += (c - b) * a[b];
          Console.WriteLine(sum);
          a[c] += a[b];
          a[b] = 0;
        }
      }
    }