#include <bits/stdc++.h>
using namespace std;
long long factorial(long long n) {
  return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
int max3(int a, int b, int c) { return max(a, max(c, b)); }
int gcd(int a, int b) {
  if (a == 0) {
    return b;
  } else {
    return gcd(b % a, a);
  }
}
long long power(long long a, long long n) {
  if (n == 1)
    return a;
  else if (n == 0)
    return 1;
  else {
    long long r = power(a, n / 2);
    if (n % 2 == 0)
      return r * r;
    else
      return r * a * r;
  }
}
long long nCr(long long n, long long r) {
  return ((factorial(n)) / (factorial(n - r) * factorial(r)));
}
void dfs(vector<vector<int> >& v, vector<int>& check, int start) {
  check[start - 1] = 1;
  for (long long j = 0; j < v[start - 1].size(); j++) {
    if (!check[v[start - 1][j] - 1]) {
      dfs(v, check, v[start - 1][j]);
    }
  }
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  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;
}
int i, j;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  vector<int> arr(100001);
  for (int i = 0; i < t; i++) {
    int num;
    cin >> num;
    arr[num]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    arr[c] += arr[b];
    arr[b] = 0;
    long long sum = 0;
    for (int j = 0; j < 100001; j++) {
      sum += arr[j] * j;
    }
    cout << sum << "\n";
  }
  return 0;
}
