#include <bits/stdc++.h>
using namespace std;
int T,n,k,x,ostatak;
long long b,potrebno;
int mini(int a){return (a+1)*a/2;}
int main(){
  cin>>T;
  while(T--){
    cin>>n>>b>>k;
    x=n/k;
    ostatak=n%k;
    potrebno=k*mini(x)+ostatak*(x+1);
    cout<<potrebno<<endl;
    if(potrebno<=b){
        cout<<"Tak"<<endl;
    }
    else cout<<"Nie"<<endl;
  }
  return 0;
}