#include <iostream>
#include <vector>

struct Person
{
    int height;
    int age;
    double cenpery;
    void grow();
};

int main()
{
    unsigned int n, speed, persons;
    int midget = 0;
    Person person;
    std::vector<Person> container;
    container.reserve(100000);
    std::cin >> n;
    for (int i = 0; i < n; ++i)
    {
        midget = 0;
        std::cin >> speed;
        std::cin >> persons;
        for (int j = 0; j < persons; ++j)
        {
            std::cin >> person.height;
            std::cin >> person.age;
            std::cin >> person.cenpery;
            container.push_back(person);
        }
        for (int j = 0; j < 21; ++j)
        {
            for (int k = 0; k < container.size(); ++k)
                if (container[midget].height > container[k].height)
                    midget = k;
            std::cout << j << ": " << 5 * speed * speed + container[midget].height << std::endl;
            for (int k = 0; k < container.size(); ++k)
                container[k].grow();
        }
        container.clear();
    }
    return 0;
}

void Person::grow()
{
    if (++age < 20)
        height += cenpery;
}
