#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000007;
const long long mod = 1000000007;
const double PI = 3.14159265358979323846;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int cans(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
int main() {
  vector<int> mp(100010, 0);
  int N, Q;
  cin >> N;
  int A[N];
  int sum = 0;
  for (int i = 0; i < (N); i++) {
    cin >> A[i];
    mp[A[i]] += 1;
    sum += A[i];
  }
  cin >> Q;
  vector<int> ans;
  for (int i = 0; i < (Q); i++) {
    int b, c;
    cin >> b >> c;
    int mul = mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    sum = sum + (c - b) * mul;
    ans.push_back(sum);
  }
  for (int i = 0; i < (Q); i++) cout << ans[i] << endl;
  return 0;
}
