#include <bits/stdc++.h>
#pragma warn + xxx
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int dr[] = {0, 1, -1, 0, 1, -1, 1, -1};
int dc[] = {1, 0, 0, -1, 1, -1, -1, 1};
long long exp(long long n, long long m, long long md) {
  long long a = 1;
  while (m > 0) {
    if (m & 1) a = (a * n % md) % md;
    m /= 2;
    n = (n * n) % md;
  }
  return a % md;
}
void disp(vector<int> v) {
  for (auto u : v) cout << u << " ";
  cout << "\n";
}
void go1() {}
void go2() {
  int n;
  cin >> n;
  long long a[n], i, j, k;
  int q;
  long long sum = 0;
  map<long long, long long> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    ++m[a[i]];
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    long long r, s;
    cin >> r >> s;
    sum -= m[r] * r;
    sum += m[r] * s;
    m[s] += m[r];
    m[r] = 0;
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tt = 1;
  while (tt--) {
    go1();
  }
  return 0;
}
