二分。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 200500
#define inf 3000000000LL
using namespace std;
long long t,n,s[maxn],e[maxn],d[maxn],cnt;
long long find(long long x)
{
long long ret=;
for (long long i=;i<=n;i++)
{
if (x>e[i]) ret+=(e[i]-s[i])/d[i]+;
else if (x>=s[i]) ret+=(x-s[i])/d[i]+;
}
return ret;
}
void work()
{
scanf("%lld",&n);cnt=;
for (long long i=;i<=n;i++)
scanf("%lld%lld%lld",&s[i],&e[i],&d[i]);
long long l=,r=inf,ans=-;
while (l<=r)
{
long long mid=l+r>>,ret=find(mid);
if (ret%) {ans=mid;r=mid-;}
else l=mid+;
}
if (ans==-) printf("Poor QIN Teng:(\n");
else
{
for (int i=;i<=n;i++)
{
if ((ans>=s[i]) && (ans<=e[i]) && ((ans-s[i])%d[i]==))
cnt++;
}
printf("%lld %lld\n",ans,cnt);
}
}
int main()
{
scanf("%lld",&t);
for (long long i=;i<=t;i++)
work();
return ;
}