#include <array>
#include <iostream>
#include <map>
#include <vector>

template <typename Map, typename Value = typename Map::mapped_type>
Value &
MapIncrementCount(Map &map, typename Map::key_type key, Value value)
{
    auto [it, flag] = map.try_emplace(key, 0);
    (void)flag;
    auto &v = it->second;
    v += value;
    return v;
}

int
main()
{
    std::size_t n;
    std::cin >> n;
    std::vector<int> inputs;
    inputs.reserve(n);
    for (std::size_t i = 0; i<n; ++i)
    {
        int input;
        std::cin >> input;
        inputs.emplace_back(input);
    }

    std::size_t operationCount;
    std::cin >> operationCount;
    std::vector<std::pair<int, int>> operations;
    operations.reserve(operationCount);
    for (std::size_t i = 0; i<operationCount; ++i)
    {
        int b, c;
        std::cin >> b >> c;
        operations.emplace_back(b, c);
    }

    long long sum = 0;
    std::map<int, int> valueCounts;
    for (auto &input : inputs)
    {
        MapIncrementCount(valueCounts, input, 1);
        sum += input;
    }

    for (std::size_t i = 0; i<operationCount; ++i)
    {
        auto &[b, c] = operations[i];

        auto findB = valueCounts.find(b);
        if (findB==valueCounts.end())
        {
            std::cout << sum << "\n";
            continue;
        }

        sum -= findB->first*findB->second;
        sum += c*findB->second;

        MapIncrementCount(valueCounts, c, findB->second);
        valueCounts.erase(b);
        std::cout << sum << "\n";
    }
}
