#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Pair{
int y;
int x;
int r;
};
struct TreeNode{
vector<TreeNode*> children;
};
Pair wall[101];
int longest;
int N, T;
int sq(int x){
return x * x;
}
bool enclose(int a, int b){
if(wall[a].r <= wall[b].r) return false;
int y1 = wall[a].y;
int x1 = wall[a].x;
int r1 = wall[a].r;
int y2 = wall[b].y;
int x2 = wall[b].x;
int r2 = wall[b].r;
if(sq(r1 - r2) <= sq(x1 - x2) + sq(y1 - y2)){
return false;
}
return true;
}
bool isChild(int parent, int child){
if(parent == child) return false;
if(!enclose(parent, child)) return false;
for(int i = 0 ; i < N; i++){
if(i == parent || i == child) continue;
if(enclose(parent, i) && enclose(i, child)) return false;
}
return true;
}
TreeNode* getTree(int root){
TreeNode* node = new TreeNode();
for(int i = 0 ; i < N; i++){
if(isChild(root, i)){
node->children.push_back(getTree(i));
}
}
return node;
}
int height(TreeNode* root){
int s = root->children.size();
vector<int> heights;
for(int i = 0 ; i < s; i++){
heights.push_back(height(root->children[i]));
}
if(heights.empty()) return 0;
int h_s = heights.size();
if(h_s >= 2){
sort(heights.begin(), heights.end());
longest = max(longest, heights[h_s - 1] + heights[h_s - 2] + 2);
}
return heights.back() + 1;
}
bool cmp(Pair a, Pair b){
if(a.r < b.r) return false;
return true;
}
int main(void){
scanf("%d", &T);
while(T--){
longest = 0;
scanf("%d", &N);
for(int i = 0 ; i < N; i++){
int x, y, r;
scanf("%d %d %d", &x, &y, &r);
wall[i] = {y, x, r};
}
sort(wall, wall + N, cmp);
TreeNode* root = getTree(0);
printf("%d\n", max(longest, height(root)));
}
}