const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  if (c % 2) {
    c++;
    return;
  }

  const arr = d.split(' ').map(Number);
  const results = arr.slice();
  let ans = 0;

  for (let i = 0; i < arr.length; i++) {
    let next = i + arr[i];
    if (next < arr.length) {
      results[next] = Math.max(results[i] + arr[next], results[next]);
    }
  }

  console.log(Math.max(...results));

  c++;
});

"use strict"

let iter = parseInt(readline());

for(let i = 0; i < iter; i++){
    let length = parseInt(readline());
    let arr = readline().split(" ").map(x => parseInt(x));
    let sumMax = 0;

    for(let j = 0; j < length; j++){
        if(arr[j] === 0){
            continue;
        }
        let sumTemp = 0;
        let num;
        for(let k = j; k < length; k += num){
            num = arr[k];
            if(num === 0){
                break;
            }
            sumTemp += num;
            arr[k] = 0;
        }

        if(sumTemp > sumMax){
            sumMax = sumTemp;
        }
    }
    print(sumMax);
}

"use strict"
let t = Number(readline());
while(t--){
	let n = Number(readline());
	let arr = readline().split(' ');
	let resArr = []
	for(let i = n - 1; i >= 0; i--){
		let a = Number(arr[i]);
		resArr[i] = a;
		if(i + a < n) resArr[i] += resArr[i+a];
	}
	print(resArr.reduce((a,b) => a > b ? a : b));
}

var tests = parseInt(readline());
for (var test = 0; test < tests; test++) {
    var size = parseInt(readline());
    var arr = readline().split(' ').map((v) => parseInt(v));
    var mem = [];
    for (var i = arr.length-1; i >= 0; i--) {
        mem[i] = calculate(mem, arr, i);
    }
    print(Math.max(...mem));
}

function calculate(mem, arr, index) {
    var acc = arr[index], nextIndex = index + arr[index];
    if (nextIndex < arr.length) {
        acc += mem[nextIndex];
    }
    mem[index] = acc;
    return mem[index];
}

var tests = parseInt(readline());
for (var test = 0; test < tests; test++) {
    var size = parseInt(readline());
    var arr = readline().split(' ').map((v) => parseInt(v));
    var mem = [];
    for (var i = arr.length-1; i >= 0; i--) {
        mem[i] = calculate(mem, arr, i);
    }
    print(Math.max(...mem));
}

function calculate(mem, arr, index) {
    var acc = 0, i = index;
    while (i < arr.length) {
        if (mem[i] != undefined) {
            acc += mem[i];
            break;
        }
        acc += arr[i];
        i += arr[i];
    }
    mem[index] = acc;
    return mem[index];
}

var limit = parseInt(readline());
var input = new Array();
for (var i = 0; i < limit; i++) {
    input.push(readline());
    input.push(readline());
}
var output = calc(input);
output.forEach(function (value) { print(value); });
function calc(inputArray) {
    var result = new Array();
    for (var i = 0; i < inputArray.length; i += 2) {
        var caseLength = parseInt(inputArray[i]);
        var caseArray = inputArray[i + 1].split(" ");
        var caseIntArray = new Array(inputArray.length);
        var maxTotal = 0;
        for (var j = (caseLength - 1); j >= 0; j--) {
            var currentValue = parseInt(caseArray[j]);
            if ((j + currentValue) < caseLength) {
                currentValue += caseIntArray[j + currentValue];
            }
            caseIntArray[j] = currentValue;
            if (maxTotal < currentValue)
                maxTotal = currentValue;
        }
        result.push(maxTotal);
    }
    return result;
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let dp = new Array(n).fill(0);
    for (let i = n - 1; i >= 0; i--) {
      let j = i;
      dp[i] += arr[j];
      if (j + arr[j] < n) {
        dp[i] += arr[j + arr[j]];
        arr[j] = dp[i];
      }
    }
    let max = 0;
    for (let i = 0; i < n; i++) max = Math.max(max, dp[i]);
    console.log(max);
  }
};
solve();

let inputString = '';
let currentLine = 0;
process.stdin.on('data', (data) => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map((str) => str.trim());
	main();
});
function readLine() {
	return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
	for (var a = arguments, r = a[0], i = a.length; --i; )
		r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
	return r;
}
function inv(b) {
	for (var a = MOD, u = 0, v = 1, t; b; v = t)
		(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
	u %= MOD;
	return u < 0 ? u + MOD : u;
}
function pow(base, n) {
	if (n === 0) return 1;
	let p = pow(base, Math.floor(n / 2));
	let res = mul(mod(p), mod(p));
	if (n % 2 === 1) res = mul(mod(res), base);
	return res;
}
function highestOneBit(i) {
	i |= i >> 1;
	i |= i >> 2;
	i |= i >> 4;
	i |= i >> 8;
	i |= i >> 16;
	return i - (i >>> 1);
}
function permutation(arr, len, store = '', permutations = []) {
	if (store.length === len) {
		permutations.push(store);
		return;
	}
	for (let i = 0; i < arr.length; i++) {
		const newArr = [...arr];
		const newChar = newArr.splice(i, 1);
		permutation(newArr, len, store.concat(newChar), permutations);
	}
	return permutations;
}

function main() {
	let t = +readLine();
	while (t--) {
		const len = +readLine();
		const arr = readLine().split(' ').map(Number);

		for (let i = len - 1; i >= 0; i--) {
			if (i + arr[i] < len) {
				arr[i] += arr[i + arr[i]];
			}
		}
		console.log(`${Math.max(...arr)}`);
	}
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  if (c % 2) {
    c++;
    return;
  }

  const arr = d.split(' ').map(Number);
  const results = arr.slice();

  for (let i = 0; i < arr.length; i++) {
    let next = i + arr[i];
    if (next < arr.length) {
      results[next] = Math.max(results[i] + arr[next], results[next]);
    }
  }

  console.log(Math.max(...results));

  c++;
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var stdin_str = '';
var stdin_lines = [];
var cur_line = 0;
function readline() {
    return stdin_lines[cur_line++];
}
process.stdin.on('data', function (raw) {
    stdin_str += raw;
});
process.stdin.on('end', function () {
    stdin_lines = stdin_str.trim().split("\n").map(function (l) { return l.trim(); });
    main();
});
var psi = function (n) { return parseInt(n, 10); };
function f_naive(i, arr) {
    var id = i, score = 0;
    while (id < arr.length) {
        score += arr[id];
        id += arr[id];
    }
    return score;
}
function solve_naive(arr) {
    var max_score = -1;
    for (var i = 0; i < arr.length; i++) {
        max_score = Math.max(max_score, f_naive(i, arr));
    }
    return max_score;
}
function f(i, arr, cache) {
    var id = i;
    if (id + arr[id] < arr.length) {
        cache[id] = arr[id] + cache[id + arr[id]];
    }
    else {
        cache[id] = arr[id];
    }
}
function solve(arr) {
    var cache = Array(arr.length);
    var max_score = -1;
    for (var i = arr.length - 1; i >= 0; i--) {
        f(i, arr, cache);
        max_score = Math.max(max_score, cache[i]);
    }
    return max_score;
}
function main() {
    var nt = psi(readline());
    var _loop_1 = function (_) {
        readline();
        var arr = [];
        readline().split(" ").map(function (n) { return arr.push(psi(n)); });
        console.log(solve(arr));
    };
    for (var _ = 0; _ < nt; _++) {
        _loop_1(_);
    }
}

let inputString = '';
let currentLine = 0;
process.stdin.on('data', (data) => {
    inputString += data;
})
process.stdin.on('end', function (){
    inputString = inputString
        .trim()
        .split('\n')
        .map((str) => str.trim());
    main();
})
function readLine(){
    return inputString[currentLine++];
}

function main(){
    let t = +readLine();
    while(t--){
        let n = +readLine();
        let a = readLine().split(' ').map(Number);
        let dp = [], ans = 0;
        for(let i=0; i<n; i++){
            dp[i] = 0;
        }
        for(let i=n-1; i>=0; i--){
            dp[i] = a[i];
            let j = i + a[i];
            if(j < n){
                dp[i] += dp[j];
            }
            ans = Math.max(ans, dp[i]);
        }
        console.log(ans);
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function main() {
  const x = readline();

  for (let i = 0; i < x; i++) {
    let n = readline();
    let arr = readline().split(' ').map(x => +x);

    const calculated = {};

    let max = 0;

    for (let i = n; i > 0; i--) {
      let s = i;
      let ans = 0;

      while (s <= n) {
        if (calculated[s]) {
          ans += calculated[s];
          break;
        } else {
          ans += arr[s - 1];
          s += arr[s - 1];
        }
      }
      calculated[i] = ans;
      if (ans > max) {
        max = ans;
      }
    }

    console.log(max);
  }
}

const solve = (n, a) => {
    let map = new Map();
    let max = 0;
    for (let i = n - 1; ~i; i--) {
        let idx = i + 1;
        let sum = 0;
        while (idx <= n) {
            if (map.has(idx)) {
                sum += map.get(idx);
                break;
            }
            sum += a[idx - 1];
            idx += a[idx - 1];
        }
        max = Math.max(max, sum);
        map.set(i + 1, sum);
    }
    console.log(max);
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            let data = input.slice(i, i + 2);
            solve(data[0][0], data[1]);
            i += 2;
        }
    });
};

main()

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var n = Number(readline());
        var sum = 0
        var number = 0
        var answer = []
        var xx = 0
        var array = readline().split(' ').map((x, i) => {
            xx = Number(x)
            answer[i + xx] = Math.max(xx + (answer[i] ? answer[i] : 0), answer[i + xx] ? answer[i + xx] : 0)
            answer[i] = (answer[i] ? answer[i] : 0) + xx
            return xx
        });
        var max = 0
        var i = 0
        var x = 0
        while (i < n) {
            x = answer[i]
            if (x > max) max = x
            i++
        }
        console.log(max)
        // console.log(answer)
    })

}

const readline = require("readline").createInterface({
    input: process.stdin,
    output: process.stdout,
});

let nTestCases = 0,
    n,
    t,
    arr = [];

let lineCnt = 0;
readline.on("line", (line) => {
    lineCnt++;

    if (lineCnt === 1) nTestCases = parseInt(line);
    else if (lineCnt % 2 === 0) n = parseInt(line);
    else {
        arr = line.split(" ").map((ele) => parseInt(ele));

        let result = 0;

        const cached = {};

        for (let i = 0; i < n; ++i) {
            let path = i + 1 + arr[i];
            let temp = arr[i];
            while (path <= n) {
                if (cached[path]) {
                    break;
                }
                cached[path] = true;
                temp += arr[path - 1];
                path = path + arr[path - 1];
            }
            if (temp > result) result = temp;
        }
        console.log(result);
    }

    if (lineCnt >= nTestCases * 2 + 1) {
        readline.close();
    }
});

// const n = 3;
// const arr = [2,1,4];
// let result = 0;

// const cached = {};

// for (let i = 0; i < n; ++i) {
//     let path = i + 1 + arr[i];
//     let temp = arr[i];
//     while (path <= n) {
//         if (cached[path]) {
//             break;
//         }
//         cached[path] = true;
//         temp += arr[path - 1];
//         path = path + arr[path - 1];
//     }
//     if (temp > result) result = temp;
// }
// console.log(result);

const write = out => process.stdout.write(out + `\n`);

const mainCode = ([l1, l2]) => {
	l2 = l2.split(' ').map(Number);
	const hashmap = {};
	let highest = 0;

	let i = l2.length - 1;
	while (i >= 0) {
		if (i + l2[i] >= l2.length) hashmap[i] = l2[i];
		else {
			if (l2[i] == 0) hashmap[i] = 0;
			else {
				hashmap[i] = l2[i] + hashmap[i + l2[i]];
			}
		}

		if (hashmap[i] > highest) highest = hashmap[i];
		i--;
	}

	write(highest);
}

let counter = 0;
let t = 0;
const t_size = 2;

const cases = [];

const lineInterpreter = (line) => {
	if (counter == 0) t = Number(line)
	else {
		const cursor = (counter - 1) % t_size
		if (cursor == 0) cases.push([line])
		else cases[cases.length - 1].push(line)
	}

	if (counter == (t * t_size)) {
		cases.map(_case => mainCode(_case))
	}
	counter++
}

const platform = 1;

if (platform > 0) {

	// FOR CODEFORCES

	process.stdin.resume();
	process.stdin.setEncoding('utf-8');

	let inputString = '';
	let currentLine = 0;

	process.stdin.on('data', inputStdin => {
	    inputString += inputStdin;
	});

	process.stdin.on('end', _ => {
	    inputString = inputString.trim().split('\n').map(string => {
	        return string.trim();
	    });

		inputString.map(line => lineInterpreter(line));
	});
} else {

	// FOR PERSONAL USE

	const sample = `4
5
7 3 1 2 3
3
2 1 4
6
2 1000 2 3 995 1
5
1 1 1 1 1`;
	sample.split(`\n`).map(line => lineInterpreter(line));
}

const longJumps = a => {
  let res = 0;
  const n = a.length;
  const dp = Array(n).fill(0);
  for (let i = 0; i < n; i++) {
    dp[i] = dp[i] + a[i];
    res = Math.max(res, dp[i]);
    if (i + a[i] < n) {
      dp[i + a[i]] = Math.max(dp[i + a[i]], dp[i]);
    }
  }
  return res;
};

const main = () => {
  let test = parseInt(readline());
  while (test--) {
    readline();
    const a = readline()
      .split(" ")
      .map(s => parseInt(s));
    console.log(longJumps(a));
  }
};

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
  inputString += inputStdin;
});

process.stdin.on("end", () => {
  inputString = inputString
    .trim()
    .split("\n")
    .map(string => string.trim());
  main();
});

const readline = () => {
  return inputString[currentLine++];
};

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function getArray(str) {
    return str.split(' ').map(x => Number(x));
}

function getInt(str) {
    return Number(str);
}

function getStrArray(str) {
    return str.split(' ').map(x => x);
}

function create2DArray(rows) {
    var arr = [];

    for (var i = 0; i < rows; i++) {
        arr[i] = [];
    }

    return arr;
}
// ---------------------------------------

function main() {
    let t = getInt(readline());
    while (t--) {
        let len = getInt(readline());
        let arr = getArray(readline());
        let resultArr = new Array(len);
        resultArr.fill(0);
        for(let i = len-1; i>=0; i--) {
            resultArr[i] = arr[i] + (resultArr[i + arr[i]] ? resultArr[i + arr[i]] : 0);
        }
        let max = 0;
        for(let i=0; i< len; i++) {
            max = Math.max(max, resultArr[i]);
        }
        console.log(max);
    }
}

let i = '';
process.stdin.on('data', (c) => (i += c));
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL).filter((line) => line);
    console.log(processInput(lines));
});

const processInput = (lines) => {
    return lines
        .slice(1)
        .filter((_, i) => i % 2)
        .map((line) => line.split(' ').map((n) => +n))
        .map((nums) => {
            const mapOfScores = new Map();
            for (let i = nums.length - 1; i >= 0; i--) {
                let j = i + nums[i];
                while (j < nums.length) {
                    if (mapOfScores.has(j)) {
                        j += mapOfScores.get(j);
                        break;
                    }
                    j += nums[j];
                }
                mapOfScores.set(i, j - i);
            }
            return Math.max(...mapOfScores.values());
        })
        .join('\n');
};

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray(N);
		var dp = new Array(N).fill(0);
		var max = 0;
		for(var j = N - 1; j >= 0; j--){
			if(j + list[j] >= N){
				dp[j] = Math.max(list[j], dp[j]);
			}else{
				dp[j] += list[j] + dp[j + list[j]];
			}
			max = Math.max(max, dp[j]);
		}
		myout(max);
	}
}

let i = '';
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);

    const t = parseInt(lines[0]);

    for (let i = 1; i <= t * 2; i += 2) {
        const n = parseInt(lines[i]);
        const arr = lines[i + 1].split(' ').map(num => parseInt(num));

        console.log(solve(n, arr));
    }
});

function solve(n, arr) {
    const result = [];
    let max = 0;
    let bestIndex = 0;

    for (let i = arr.length - 1; i >= 0; i--) {
        result[i] = arr[i];

        if (i + arr[i] < arr.length) {
            result[i] += result[i + arr[i]];
        }

        if (result[i] > max) {
            max = result[i];
            bestIndex = i;
        }
    }

    return max;
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let dp = new Array(n).fill(0);
    for (let i = n - 1; i >= 0; i--) {
      let j = i;
      dp[i] += arr[j];
      if (j + arr[j] < n) dp[i] += arr[j + arr[j]];
    }
    let max = 0;
    for (let i = 0; i < n; i++) max = Math.max(max, dp[i]);
    console.log(max);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let max = 0;
    for (let i = 0; i < n; i++) max = Math.max(arr[i], max);
    let vis = 0;
    for (let i = 0; i < n; i++) {
      let v = 0,
        j = i;
      while (j < n) {
        v += arr[j];
        j += arr[j];
        vis++;
      }
      max = Math.max(v, max);
      if (vis >= n * 2) break;
    }
    console.log(max);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let max = 0,
      vis = 0;
    for (let i = 0; i < n; i++) {
      let v = 0,
        j = i;
      while (j < n) {
        v += arr[j];
        j += arr[j];
        vis++;
      }
      max = Math.max(v, max);
      if (vis >= n * 2) break;
    }
    console.log(max);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let max = 0,
      vis = 0;
    for (let i = 0; i < n; i++) {
      let v = 0,
        j = i;
      while (j < n) {
        v += arr[j];
        j += arr[j];
        vis++;
      }
      max = Math.max(v, max);
      if (vis === n) break;
    }
    console.log(max);
  }
};
solve();

let inputString = '';
let currentLine = 0;
process.stdin.on('data', (data) => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map((str) => str.trim());
	main();
});
function readLine() {
	return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
	for (var a = arguments, r = a[0], i = a.length; --i; )
		r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
	return r;
}
function inv(b) {
	for (var a = MOD, u = 0, v = 1, t; b; v = t)
		(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
	u %= MOD;
	return u < 0 ? u + MOD : u;
}
function pow(base, n) {
	if (n === 0) return 1;
	let p = pow(base, Math.floor(n / 2));
	let res = mul(mod(p), mod(p));
	if (n % 2 === 1) res = mul(mod(res), base);
	return res;
}
function highestOneBit(i) {
	i |= i >> 1;
	i |= i >> 2;
	i |= i >> 4;
	i |= i >> 8;
	i |= i >> 16;
	return i - (i >>> 1);
}
function permutation(arr, len, store = '', permutations = []) {
	if (store.length === len) {
		permutations.push(store);
		return;
	}
	for (let i = 0; i < arr.length; i++) {
		const newArr = [...arr];
		const newChar = newArr.splice(i, 1);
		permutation(newArr, len, store.concat(newChar), permutations);
	}
	return permutations;
}

function main() {
	let t = +readLine();
	while (t--) {
		const len = +readLine();
		const _arr = readLine().split(' ').map(Number);
		const arr = [];
		for (let i = 0; i < len; i++) {
			if (_arr[i] === _arr[i + 1]) {
				let [count, j] = [0, i];
				while (_arr[j] === _arr[j + 1]) {
					count += _arr[j];
					j++;
				}
				arr.push(_arr[i] + count);
				i = j;
			} else arr.push(_arr[i]);
		}
		let max = 0;
		for (let i = 1; i <= arr.length; i++) {
			let [c, j] = [0, i];
			while (j <= arr.length) {
				c += arr[j - 1];
				j += arr[j - 1];
			}
			max = Math.max(max, c);
		}
		console.log(max);
	}
}

let inputString = '';
let currentLine = 0;
process.stdin.on('data', (data) => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map((str) => str.trim());
	main();
});
function readLine() {
	return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
	for (var a = arguments, r = a[0], i = a.length; --i; )
		r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
	return r;
}
function inv(b) {
	for (var a = MOD, u = 0, v = 1, t; b; v = t)
		(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
	u %= MOD;
	return u < 0 ? u + MOD : u;
}
function pow(base, n) {
	if (n === 0) return 1;
	let p = pow(base, Math.floor(n / 2));
	let res = mul(mod(p), mod(p));
	if (n % 2 === 1) res = mul(mod(res), base);
	return res;
}
function highestOneBit(i) {
	i |= i >> 1;
	i |= i >> 2;
	i |= i >> 4;
	i |= i >> 8;
	i |= i >> 16;
	return i - (i >>> 1);
}
function permutation(arr, len, store = '', permutations = []) {
	if (store.length === len) {
		permutations.push(store);
		return;
	}
	for (let i = 0; i < arr.length; i++) {
		const newArr = [...arr];
		const newChar = newArr.splice(i, 1);
		permutation(newArr, len, store.concat(newChar), permutations);
	}
	return permutations;
}

function main() {
	let t = +readLine();
	while (t--) {
		const len = +readLine();
		const arr = readLine().split(' ').map(Number);
		let [i, count] = [1, 0];
		while (i <= len) {
			count += arr[i - 1];
			i += arr[i - 1];
		}
		const max = Math.max(...arr);
		const min = Math.min(...arr);

		let cMax = 0;
		let index = arr.findIndex((item) => item === max);
		while (index < len) {
			cMax += arr[index];
			index += arr[index];
		}
		count = Math.max(count, cMax);

		let cMin = 0;
		let minIndex = arr.findIndex((item) => item === min);
		while (minIndex < len) {
			cMax += arr[minIndex];
			minIndex += arr[minIndex];
		}
		count = Math.max(count, cMin);

		if (count < max) console.log(max);
		else console.log(count);
	}
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var n = Number(readline());
        var sum = 0
        var number = 0
        var answer = []
        var xx = 0
        var array = readline().split(' ').map((x, i) => {
            xx = Number(x)
            answer[i + xx] = (answer[i]?answer[i] : 0) + Math.max(xx, answer[i + xx]?answer[i + xx] : 0)
            answer[i] = (answer[i]?answer[i] : 0) + xx
            // console.log((answer[i]?answer[i] : 0) + xx)
            // console.log(answer)

            return xx
        });
        var max = 0
        var i = 0
        var x = 0
        while(i<n){
            x = answer[i]
            if (x > max) max = x
            i++
        }
        console.log(max)
        // console.log(answer)
    })

}

"use strict"

let iter = parseInt(readline());

for(let i = 0; i < iter; i++){
    let length = parseInt(readline());
    let arr = readline().split(" ").map(x => parseInt(x));
    let sumMax = 0;
    let stopFlag = arr[0] > length - 1 ? 1 : arr[0];

    for(let j = 0; j < stopFlag; j++){
        let sumTemp = 0;
        for(let k = j; k < length; k += arr[k]){
            sumTemp += arr[k];
        }

        if(sumTemp > sumMax){
            sumMax = sumTemp;
        }
    }
    print(sumMax);
}


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const T = readline();
    for (let i = 0; i < T; i++) {
        const n = readline()
        let arr = []
        for (let j = 0; j < n; j++) {
            arr.push(readline())
        }
        solve(arr)
    }
}
function solve(arr) {
    let tot = 0
    let map = new Map()
    for (let i = arr.length - 1; i >=0 ; i--) {
        let pos = arr.length
        let cnt = 0
        if (map.has(arr[i])) {
            [pos, cnt] = map.get(arr[i])
        }

        let s1 = arr[i]
        for (let j = i + 1; j < pos; j++) {
            let s2 = arr[j]
            if (s1[0] === s2[0] && s1[1] !== s2[1] || s1[0] !== s2[0] && s1[1] === s2[1]) {
                cnt++;
            }
        }

        tot += cnt
        map.set(arr[i], [i, cnt])

    }

    console.log(tot)
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  inputString = inputString
    .trim()
    .split('\n')
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  let _t = parseInt(readline());
  // let _t = 1;
  while (_t--) {
    let n = parseInt(readline());
    let m = [],
      a = [];
    for (let i = 0; i < n; i++) {
      let s = readline();
      a.push(s);
      if (m[s]) m[s]++;
      else m[s] = 1;
    }
    let ans = 0;
    a.forEach((e) => {
      for (let i = 9; i < 36; i++) {
        let c = i.toString(36);
        if (c === e[0]) continue;
        let cur = c + e[1];
        ans += m[cur] ? m[cur] : 0;
      }
      for (let i = 9; i < 36; i++) {
        let c = i.toString(36);
        if (c === e[1]) continue;
        let cur = e[0] + c;
        // console.log(cur);
        ans += m[cur] ? m[cur] : 0;
      }
    });
    console.log(ans / 2);
  }
}

// cat input.txt | node main.js

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const calc = (n, a)=>{
    let chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'];
    let result = BigInt(0);

    let mapStart = {};
    let mapEnd = {};
    let mapBoth = {};

    for (let i = 0; i < n; i++) {
        // mapStart[a[i][0]] = (mapStart[a[i][0]] || 0) + 1;
        // mapEnd[a[i][1]] = (mapEnd[a[i][1]] || 0) + 1;

        // pairs like a[i][0] + chars[j]
        for (let j = 0; j < chars.length; j++) {
            if (chars[j] === a[i][1]) continue;
            result += mapBoth[`${a[i][0]}${chars[j]}`] || 0n;
        }

        // pairs like chars[j] + a[i][1]
        for (let j = 0; j < chars.length; j++) {
            if (chars[j] === a[i][0]) continue;
            result += mapBoth[`${chars[j]}${a[i][1]}`] || 0n;
        }

        mapBoth[a[i]] = (mapBoth[a[i]] || 0n) + 1n;
    }

    // console.log(`DEBUG mapStart`, mapStart);
    // console.log(`DEBUG mapEnd`, mapEnd);
    // console.log(`DEBUG mapBoth`, mapBoth);

    // for (let i = 0; i < chars.length; i++) {
    //     for (let j = i; j < chars.length; j++) {
    //         if (mapStart[chars[i]]) result += BigInt(cnk(mapStart[chars[i]], 2));
    //         if (mapEnd[chars[j]]) result += BigInt(cnk(mapEnd[chars[j]], 2));
    //         let pair = `${chars[i]}${chars[j]}`;
    //         if (mapBoth[pair]) result -= BigInt(2 * cnk(mapBoth[pair], 2));
    //     }
    //     console.log(`DEBUG result for ${i}`, result);
    // }

    return result;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let a = [];
        for (let i = 0; i < n; i++) {
            a.push(readline());
        }
        console.log(`${calc(n, a)}`);
    }
}

'use strict';
 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}
const L = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;
const ra = ()=>readline().split(' ').map(a=>+a)

let ca = "a".charCodeAt(0);
const compose = (n0, n1)=>{
  return (1<<n0)|(1<<(11+n1))
};
const calc = (n, A)=>{
  let map = new Map();
  let ans = 0;
  for (let s of A){
    L({s})
    let n0 = s.charCodeAt(0)-ca;
    let n1 = s.charCodeAt(1)-ca;
    for (let i=0; i<=10; i++){
      if (i!=n0){
        let a = compose(i, n1);
        ans += map.get(a)||0;
        if (map.get(a))
          L('ADD1', a.toString(2), map.get(a))
      }
      if (i!=n1){
        let a = compose(n0, i);
        ans += map.get(a)||0;
        if (map.get(a))
          L('ADD2', a.toString(2), map.get(a))
      }
    }
    let a = compose(n0, n1);
    map.set(a, (map.get(a)||0)+1)
    L('SET', a.toString(2), 1)
  }
  return ans;
};

function main() {
    let T = +readline()
    while (T--){
      let [n] = ra();
      let A = [];
      for (let i=0; i<n; i++)
        A.push(readline())
      L('Ans:')
      print(calc(n, A));
    }
}

E.calc = calc;

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		let ans = 0;
		const cnt = [];
		const cntFirst = [];
		const cntSecond = [];
		for (let i = 0; i < n; i++) {
			const s = rl();
			cnt[s] = cnt[s] || 0;
			cntFirst[s[0]] = cntFirst[s[0]] || 0;
			cntSecond[s[1]] = cntSecond[s[1]] || 0;

			ans += cntFirst[s[0]] - cnt[s];
			ans += cntSecond[s[1]] - cnt[s];
			cntFirst[s[0]]++;
			cntSecond[s[1]]++;
			cnt[s]++;
		}

		console.log(ans);
	}
}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(a) {
  const map = new Map();
  const get = char => char.charCodeAt(0) - 97;
  let res = 0n;
  for (let [l, r] of a) {
    var _map$get, _map$get2, _map$get3, _map$get4, _map$get5, _map$get6;
    let statel = 1 << get(l),
        stater = 1 << get(r) + 11,
        state = statel | stater;
    res = res + ((_map$get = map.get(statel)) !== null && _map$get !== void 0 ? _map$get : 0n) + ((_map$get2 = map.get(stater)) !== null && _map$get2 !== void 0 ? _map$get2 : 0n) - ((_map$get3 = map.get(state)) !== null && _map$get3 !== void 0 ? _map$get3 : 0n) * 2n;
    map.set(statel, ((_map$get4 = map.get(statel)) !== null && _map$get4 !== void 0 ? _map$get4 : 0n) + 1n);
    map.set(stater, ((_map$get5 = map.get(stater)) !== null && _map$get5 !== void 0 ? _map$get5 : 0n) + 1n);
    map.set(state, ((_map$get6 = map.get(state)) !== null && _map$get6 !== void 0 ? _map$get6 : 0n) + 1n);
  }
  console.log(res.toString());
}

async function main(read) {
  let t = Number(await read());
  while (t--) {
    let n = Number(await read()),
        a = [];
    while (n--) {
      a.push(await read());
    }
    solve(a);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextStrArray(N);
		var map = {};
		var alpha = "abcdefghijk";
		for(var i = 0; i < alpha.length; i++){
			for(var j = 0; j < alpha.length; j++){
				map[alpha[i] + alpha[j]] = 0;
			}
		}
		for(var i = 0; i < N; i++){
			map[list[i]]++;
		}

		var output = 0n;
		var key = Object.keys(map);
		for(var i = 0; i < key.length; i++){
			for(var j = i + 1; j < key.length; j++){
				var Li = key[i][0];
				var Ri = key[i][1];
				var Lj = key[j][0];
				var Rj = key[j][1];
				if(Li == Lj || Ri == Rj){
					output += BigInt(map[key[i]] * map[key[j]]);
				}
			}
		}
		myout(output);
	}
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines.slice(l, l + n).map(str => str.trim())
        l += n
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    n = BigInt(n)
    //
    const map = {}
    arr.forEach(x => {
        const [a, b] = x
        map[a] = map[a] || {}
        map[a][b] = (map[a][b] || 0n) + 1n
    })
// console.log(map)
// // return
    const chs = 'abcdefghijk'
    let diff = 0n
    let same = 0n
    // [i, j] [u, v]
    for (let i = 0; i < chs.length; i++) {
    for (let j = 0; j < chs.length; j++) {
        const y = cal(map, chs[i], chs[j])
        same += y * (y - 1n)
    for (let u = 0; u < chs.length; u++) {
        if (u === i) continue
    for (let v = 0; v < chs.length; v++) {
        if (v === j) continue
        const x = cal(map, chs[u], chs[v])
        diff += x * y
    }
    }
    }
    }
    const total = (n - 1n) * n
// console.log(total, diff, same)
    return (total - diff - same) / 2n
}
function cal(map, i, j) {
    return (map[i] && map[i][j]) ? map[i][j] : 0n
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = [];
    for (let i = 0; i < n; i++) {
      arr.push(readline().trim());
    }
    if (n === 1) {
      console.log("0");
      continue;
    }
    let alp = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"];
    let obj = {};
    obj[arr[n - 1]] = 1;
    let sum = 0;
    for (let i = n - 2; i >= 0; i--) {
      let k = arr[i][1];
      for (let j = 0; j < alp.length; j++) {
        if (alp[j] !== k) {
          if (obj[arr[i][0] + alp[j]]) sum += obj[arr[i][0] + alp[j]];
        }
      }
      k = arr[i][0];
      for (let j = 0; j < alp.length; j++) {
        if (alp[j] !== k)
          if (obj[alp[j] + arr[i][1]]) sum += obj[alp[j] + arr[i][1]];
      }
      if (obj[arr[i]]) obj[arr[i]] += 1;
      else obj[arr[i]] = 1;
    }
    console.log(sum);
  }
};
solve();

"use strict";
const fs = require("fs");
const { consumers } = require("stream");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = [];
    for (let i = 0; i < n; i++) {
      arr.push(readline().trim().split(""));
    }
    if(n===1) {
      console.log("0");
      continue;
    }
    let alp = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"];
    let narr = [];
    let obj = {};
    for (let i = 0; i < alp.length; i++) {
      let na = [];
      for (let j = 0; j < n; j++) {
        for (let k = 0; k < 2; k++) {
          if (arr[j][k] === alp[i]) {
            na.push(arr[j]);
            break;
          }
        }
      }
      narr.push(na);
    }
    let res = 0n;
    for (let i = 0; i < 11; i++) {
      if (narr[i].length >= 2) {
        let obj = {};
        let len = BigInt(narr[i].length);
        let sum = 0n;
        for (let j = narr[i].length - 1; j >= 0; j--) {
          let s1 = narr[i][j][0] + narr[i][j][1];
          let s2 = narr[i][j][1] + narr[i][j][0];
          if (obj[s1] || obj[s2]) {
            obj[s1]++;
          } else {
            obj[s1] = 1n;
            obj[s2] = 1n;
          }
          if (obj[s1] === 1) sum += len - (BigInt(j) + 1n);
          else sum += len - (BigInt(j) + 1n) - (obj[s1] - 1n);
        }
        res += sum;
      }
    }
    console.log(res + "");
  }
};
solve();

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const calc = (n, a)=>{
    let chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'];
    let result = BigInt(0);

    let mapStart = {};
    let mapEnd = {};
    let mapBoth = {};

    for (let i = 0; i < n; i++) {
        // mapStart[a[i][0]] = (mapStart[a[i][0]] || 0) + 1;
        // mapEnd[a[i][1]] = (mapEnd[a[i][1]] || 0) + 1;

        // pairs like a[i][0] + chars[j]
        for (let j = 0; j < chars.length; j++) {
            if (chars[j] === a[i][1]) continue;
            result += BigInt(mapBoth[`${a[i][0]}${chars[j]}`] || 0);
        }

        // pairs like chars[j] + a[i][1]
        for (let j = 0; j < chars.length; j++) {
            if (chars[j] === a[i][0]) continue;
            result += BigInt(mapBoth[`${chars[j]}${a[i][1]}`] || 0);
        }

        mapBoth[a[i]] = (mapBoth[a[i]] || 0) + 1;
    }

    // console.log(`DEBUG mapStart`, mapStart);
    // console.log(`DEBUG mapEnd`, mapEnd);
    // console.log(`DEBUG mapBoth`, mapBoth);

    // for (let i = 0; i < chars.length; i++) {
    //     for (let j = i; j < chars.length; j++) {
    //         if (mapStart[chars[i]]) result += BigInt(cnk(mapStart[chars[i]], 2));
    //         if (mapEnd[chars[j]]) result += BigInt(cnk(mapEnd[chars[j]], 2));
    //         let pair = `${chars[i]}${chars[j]}`;
    //         if (mapBoth[pair]) result -= BigInt(2 * cnk(mapBoth[pair], 2));
    //     }
    //     console.log(`DEBUG result for ${i}`, result);
    // }

    return result;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let a = [];
        for (let i = 0; i < n; i++) {
            a.push(readline());
        }
        console.log(`${calc(n, a)}`);
    }
}

'use strict';
 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}
const L = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;
const ra = ()=>readline().split(' ').map(a=>+a)

let ca = "a".charCodeAt(0);
const compose = (n0, n1)=>{
  return (1<<n0)|(1<<(11+n1))
};
const calc = (n, A)=>{
  let map = new Map();
  let ans = 0;
  for (let s of A){
    L({s})
    let n0 = s.charCodeAt(0)-ca;
    let n1 = s.charCodeAt(1)-ca;
    for (let i=0; i<10; i++){
      if (i!=n0){
        let a = compose(i, n1);
        ans += map.get(a)||0;
        if (map.get(a))
          L('ADD1', a.toString(2), map.get(a))
      }
      if (i!=n1){
        let a = compose(n0, i);
        ans += map.get(a)||0;
        if (map.get(a))
          L('ADD2', a.toString(2), map.get(a))
      }
    }
    let a = compose(n0, n1);
    map.set(a, (map.get(a)||0)+1)
    L('SET', a.toString(2), 1)
  }
  return ans;
};

function main() {
    let T = +readline()
    while (T--){
      let [n] = ra();
      let A = [];
      for (let i=0; i<n; i++)
        A.push(readline())
      L('Ans:')
      print(calc(n, A));
    }
}

E.calc = calc;


const main = async () => {
    const inputs = [];
    let times = null;

    const rl = require("readline").createInterface({
      input: process.stdin,
      output: process.stdout,
    });

    for await (const line of rl) {
      if (!times) {
        times = line;
      } else {
        if (inputs.length < times * 2 - 1) {
          inputs.push(line);
        } else {
          inputs.push(line);
          rl.close();
        }
      }
    }

    runGame(times, inputs);
  };

  const runGame = (times, inputs) => {
    for (let i = 0; i < times; i++) {
      findMatch(inputs[i * 2], inputs[i * 2 + 1]); // len, digits
    }
  };

  const findMatch = (len, digits) => {
    const arr = digits.toString(10).split("").map(Number);
    let output = 0;

    if (len % 2 === 0) {
      for (let evenIndex = 0; evenIndex < +len / 2; evenIndex++) {
        if (arr[2 * evenIndex + 1] % 2 === 0) output++;
      }
      if (output > 0) {
        console.log("2");
      } else {
        console.log("1");
      }
    } else {
      output = 0;

      for (let oddIndex = 0; oddIndex < (+len + 1) / 2; oddIndex++) {
        if (arr[(2 * oddIndex)] % 2 !== 0) output++;
      }
      if (output > 0) {
        console.log("1");
      } else {
        console.log("2");
      }
    }
  };

  main();

let readline=require('readline');
let rl=readline.createInterface({
    input:process.stdin,
    output:process.stdout
});
let arr=[],T;
rl.on('line',function(inp){
    arr.push(inp);
    let len=arr.length;
    if(len===1) T=parseInt(arr[0]);
    else if(len===2*T+1){
        for(let i=2;i<=2*T;i+=2){
            let l=arr[i].length;
            if(l%2){
                let flag=0;
                for(let j=0;j<l;j+=2){
                    if(parseInt(arr[i][j])%2){
                        flag=1;
                        break;
                    }
                }
                if(flag) console.log(1);
                else console.log(2);
            }else{
                let flag=0;
                for(let j=1;j<l;j+=2){
                    if(parseInt(arr[i][j])%2===0){
                        flag=1;
                        break;
                    }
                }
                if(flag) console.log(2);
                else console.log(1);
            }
        }
        process.exit(0);
    }
});

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const str = readLine();
    let win = false;

    if (len % 2 === 1) {
      for (let i = 0; i < len; i += 2) {
        if (+str[i] % 2 === 1) {
          win = true;
          break;
        }
      }
      if (win) console.log(1);
      else console.log(2);
    } else {
      for (let i = 1; i < len; i += 2) {
        if (+str[i] % 2 === 0) {
          win = true;
          break;
        }
      }
      if (win) console.log(2);
      else console.log(1);
    }
  }
}

// Digit Game - https://codeforces.com/problemset/problem/1419/A

const main = async () => {
  const inputs = [];
  let times = null;

  const rl = require("readline").createInterface({
    input: process.stdin,
    output: process.stdout,
  });

  for await (const line of rl) {
    if (!times) {
      times = line;
    } else {
      if (inputs.length < times * 2 - 1) {
        inputs.push(line);
      } else {
        inputs.push(line);
        rl.close();
      }
    }
  }

  runGame(times, inputs);
};

const runGame = (times, inputs) => {
  for (let i = 0; i < times; i++) {
    findMatch(inputs[i * 2], inputs[i * 2 + 1]); // len, digits
  }
};

const findMatch = (len, digits) => {
  const arr = digits.toString(10).split("").map(Number);
  let output = 0;

  if (len % 2 === 0) {
    for (let evenIndex = 0; evenIndex < +len / 2; evenIndex++) {
      if (arr[2 * evenIndex + 1] % 2 === 0) output++;
    }
    if (output > 0) {
      console.log("2");
    } else {
      console.log("1");
    }
  } else {
    output = 0;

    for (let oddIndex = 0; oddIndex < (+len + 1) / 2; oddIndex++) {
      if (arr[2 * oddIndex] % 2 !== 0) output++;
    }
    if (output > 0) {
      console.log("1");
    } else {
      console.log("2");
    }
  }
};

main();

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    // var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var t = +inputs[0];
    for (let i = 0; i < t; i++) {
        var n = +inputs[i * 2 + 1];
        var number = inputs[i * 2 + 2];
        if (n == 1) {
            console.log(number % 2 == 0 ? 2 : 1);
            continue;
        }
        if (n % 2 == 1) {
            console.log([...number].some((v, i) => i % 2 == 0 && v % 2 == 1) ? 1 : 2);
        }
        else {
            console.log([...number].some((v, i) => i % 2 == 1 && v % 2 == 0) ? 2 : 1);
        }
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    A();
});

function readline() {
    return inputString[currentLine++];
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = parseInt(a[i]);

    return a;
}

function pi(x){
    return parseInt(x);
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let s = ti(readline().split(''));

        let isEvenEven = false;
        let isOddOdd = false;
        for(let i = 0; i < n; i++){
            if((i+1) % 2 === 0){
                if(!isEvenEven){
                    isEvenEven = s[i] % 2 === 0;
                }
            }else{
                if(!isOddOdd){
                    isOddOdd = s[i] % 2 !== 0;
                }
            }
        }

        if(n % 2 === 0){
            if(isEvenEven)
                console.log(2);
            else{
                console.log(1);
            }
        }else{
            if(isOddOdd)
                console.log(1);
            else{
                console.log(2);
            }
        }
    }
}

const readline = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const digiGame = (n, _d) => {
  const arr = _d.toString(10).split("").map(Number);
  let output = 0;
  if (n % 2 === 0) {
    for (let evenIndex = 0; evenIndex < n / 2; evenIndex++) {
      if (arr[2 * evenIndex + 1] % 2 === 0) output++;
    }
    if (output > 0) {
      console.log("2");
    } else {
      console.log("1");
    }
  } else {
    output = 0;
    for (let oddIndex = 0; oddIndex < (n + 1) / 2; oddIndex++) {
      if (arr[(2 * oddIndex) % 2 === 0]) output++;
    }
    if (output > 0) {
      console.log("1");
    } else {
      console.log("2");
    }
  }
};

readline.question("", (t) => {
  for (let i = 1; i <= t; i++) {

      readline.question("", (n) => {
        readline.question("", (_d) => {
            digiGame(n, _d);
        });
      });
  }

});

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const str = readLine();
    let win = false;

    if (len % 2 === 1) {
      for (let i = 0; i < len; i += 2) {
        if (+str[i] % 2 === 1) win = true;
        break;
      }
      if (win) console.log(1);
      else console.log(2);
    } else {
      for (let i = 1; i < len; i += 2) {
        if (+str[i] % 2 === 0) win = true;
        break;
      }
      if (win) console.log(2);
      else console.log(1);
    }
  }
}


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let n = readline();
        let strings = new Array();
        let dict = {};
        let result = new Array(n).fill(0);
        for (let i = 0; i < n; i++) {
            let str = readline();
            strings.push(str);
            if (dict[str]) {
                dict[str] = 2;
            } else {
                dict[str] = 1;
            }
        }

        wordLoop: for (let i = 0; i < n; i++) {
            lengthLoop: for (let len = 1; len < strings[i].length; len++) {
                let word = strings[i].substring(0, len);
                let suffix = strings[i].substring(len);
                if (word.length === strings[i].length / 2 && dict[word] === 2 && word === suffix) {
                    result[i] = '1';
                    continue wordLoop;
                }
                if (dict[word] && dict[suffix]) {
                    result[i] = '1';
                    continue wordLoop;
                } else {
                    continue lengthLoop;
                }
            }
            result[i] = '0';
        }

        output(result.join(''));
    }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextStrArray(N);
		var set = new Set(list);
		var output = new Array(N).fill("0");
		for(var i = 0; i < N; i++){
			var s = list[i];
			var ok = false;
			for(var j = 0; j < s.length - 1; j++){
				var L = s.substring(0, j + 1);
				var R = s.substring(j + 1);

				if(set.has(L) && set.has(R)){
					ok = true;
				}
				if(L == R && set.has(L)){
					ok = true;
				}
			}
			if(ok){
				output[i] = "1";
			}
		}
		myout(myconv(output, 0));
	}
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
    var n = readline();

    var set = new Set();
    var arr = [];

    for (var j = 0; j < n; j++) {
        var str = readline();
        set.add(str);
        arr.push(str);
    }

    for (var j = 0; j < arr.length; j++) {
        for (var k = 1; k < arr[j].length; k++) {
            if (
                set.has(arr[j].substr(0, k)) &&
                set.has(arr[j].substr(k, arr[j].length))
            ) {
                arr[j] = 1;
                break;
            }
        }
        arr[j] = arr[j] === 1 ? 1: 0;
    }

    print(arr.join(''));
}

var t = +readline();

for(var i = 0; i< t; i ++) {

      var nums = [];
    var t1 = +readline();
    for(var k = 0; k < t1; k++){
      var t3 = readline();
      nums.push(t3);
    }
    print(DoubleString(nums));

}

function DoubleString(list){

   var set = new Set();

  for(var each of list){
    set.add(each);
  };

  var res = new Array(list.length).fill(0);

  for(var k = 0; k<list.length; k++){
    var word = list[k];
    for(var i = 0; i<word.length; i++){
      var l1 = word.slice(0,i);
      var l2 = word.slice(i);
      if (set.has(l1) && set.has(l2)) {
        res[k] = 1;
        break;
      }
    }

  }
  return res.join('');

}

var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        var n = parseInt(readline());
        var set = new Set();
        var arr = [];
        for (var i =0; i < n; i++) {
            arr.push(readline());
            set.add(arr[i]);
        }
        var ans = [];
        for (var i=0;i<n;i++) {
            var s = arr[i];
            var b = 0;
            for (var j=1;j<s.length;j++) {
                if (set.has(s.substring(j)) && set.has(s.substring(0, j))) {
                    b = 1;
                    break;
                }
            }
            ans.push(b);
        }
        print(ans.join(''));
    }

// // cat .\input.txt | node .\script.js
'use strict';
let data = ''; // raw
let inputs = ''; // iterator
function read() { return inputs.next().value.trim(); };

async function solve() {
    let n;
    n = parseInt(await read())
    let s = new Array(n)
    let mp = new Map()
    for (let i = 0; i < n; i++) {
        s[i] = await read()
        mp.set(s[i], true)
    }
    for (let i = 0; i < n; i++) {
        let ok = false
        for (let j = 1; j < s[i].length; j++) {
            let pref = s[i].substring(0, j)
            let suff = s[i].substring(j, s[i].length)
            if (mp.get(pref) && mp.get(suff)) { ok = true }
        }
        process.stdout.write(ok ? '1' : '0');
    }
    process.stdout.write('\n');
}

async function main() {
    let tt = parseInt(await read())
    for (let i = 0; i < tt; i++) { await solve() }
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => data += input);
process.stdin.on('end', async () => {
    let splitted = data.split('\r\n')
    inputs = await splitted.values();
    main();
});

function Solution() {
  let t = 0;
  const N = Number(lines[t++]);
  const res = [];
  for (let i = 0; i < N; i++) {
    const n = Number(lines[t++]);

    const strArr = [];
    for (let j = 0; j < n; j++) {
      strArr.push(lines[t++]);
    }

    const set = new Set(strArr);
    const r = [];

    for (let j = 0; j < n; j++) {
      const curr = strArr[j];
      let flag = false;
      for (let z = 1; z < curr.length; z++) {
        if (set.has(curr.substring(0, z)) && set.has(curr.substring(z))) {
          flag = true;
          break;
        }
      }
      if (flag) r.push(1)
      else r.push(0);
    }

    res.push(r.join(''));
  }
  return res.join('\n');
}

const readline = require('readline')

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})
const lines = []
rl.on('line', (input) => {
  lines.push(input);
})
rl.on('close', () => {
  console.log(Solution());
});

const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let lineNum = 0;
let strCnt = 0;
let curCnt = 0;
/** @type {string[]} arr */
let arr = [];
let set = new Set();

rl.on("line", line => {
    let num = Number(line);
    if (lineNum === 0) {
        // skip
    } else if (!isNaN(num)) {
        strCnt = num;
        curCnt = 0;
        set.clear();
        arr = [];
    } else {
        curCnt++;
        set.add(line);
        arr.push(line);
        if (curCnt === strCnt) {
            let ans = [];
            for (let s of arr) {
                let matched = false;
                for (let i = 1; i < s.length; i++) {
                    if (set.has(s.substring(0, i)) && set.has(s.substring(i))) {
                        matched = true;
                        break;
                    }
                }

                ans.push(matched ? "1" : "0");
            }
            console.log(ans.join(""));
        }
    }

    lineNum++;
});

const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let lineNum = 0;
let strCnt = 0;
let curCnt = 0;
/** @type {string[]} arr */
let arr = [];
let set = new Set();

rl.on("line", line => {
    let num = Number(line);
    if (lineNum === 0) {
        // skip
    } else if (!isNaN(num)) {
        strCnt = num;
        curCnt = 0;
        set.clear();
        arr = [];
    } else {
        curCnt++;
        set.add(line);
        arr.push(line);
        if (curCnt === strCnt) {
            let ans = "";
            for (let s of arr) {
                let matched = false;
                for (let i = 1; i < s.length; i++) {
                    if (set.has(s.substring(0, i)) && set.has(s.substring(i))) {
                        matched = true;
                        break;
                    }
                }

                ans += matched ? "1" : "0";
            }
            console.log(ans);
        }
    }

    lineNum++;
});

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
// console.log(input)
var T = readline();
// var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
  var n = readline()//.split(' ').map((x) => parseInt(x));
  // var a = readline().split(' ').map((x) => parseInt(x));
  var mp = new Map();
  var ans = "";
  var s = []
  for(var i=0;i<n;i++) {
    var a = readline();
    mp.set(a, 0)
    s.push(a);
  }
  // if(tc==1)console.log(s)
//   if(tc==1) console.log(mp)
  for(var i=0;i<n;i++) {
    var ok = false;
    // if(tc==1)console.log(s[i])
    for(var j=0;j<s[i].length;j++) {
      var f = s[i].slice(0, j+1);
      var se = s[i].slice(j+1, s[i].length);
      // if(tc == 1) console.log([f,se,j]);
      if(mp.has(se) && mp.has(f)) {
        ans += 1;
        ok = true;
        break;
      }
    }
    if(!ok) ans += 0;
  }
  console.log(ans)
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines.slice(l, l + n).map(str => str.trim())
        l += n
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const map = arr.reduce((o, x) => {
        o[x] = 1
        return o
    }, {})
    const ans = arr.map(x => {
        for (let i = 1; i < x.length; i++) {
            const a = x.slice(0, i)
            const b = x.slice(i)
    // console.log(a, b)
            if (map[a] && map[b]) {
                return 1
            }
        }
        return 0
    })
    return ans.join('')
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = [];
    for (let i = 0; i < n; i++) arr.push(readline().trim());
    let obj = {};
    if (n === 1) {
      console.log(0);
      continue;
    }
    for (let i = 0; i < n; i++) {
      obj[arr[i]] = 1;
    }
    let obj1 = {};
    let res = "";
    for (let i = 0; i < n; i++) {
      let flag = 0;
      if (arr[i].length > 1 && !obj1[arr[i]]) {
        let x = arr[i];
        for (let i = 1; i < x.length; i++) {
          if (obj[x.slice(0, i)] && obj[x.slice(i, x.length)]) {
            flag = 1;
            break;
          }
        }
        res += flag;
        if (flag === 0) obj1[arr[i]] = 1;
        else obj1[arr[i]] = 2;
      } else {
        if (arr[i].length === 1) res += flag;
        else {
          if (obj1[arr[i]] === 1) res += 0;
          else res += 1;
        }
      }
    }
    console.log(res);
  }
};
solve();

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
    var n = readline();

    var set = new Set();
    var arr = [];

    for (var j = 0; j < n; j++) {
        var str = readline();
        set.add(str);
        arr.push(str);
    }

    for (var j = 0; j < arr.length; j++) {
        for (var k = 1; k < arr[j].length - 1; k++) {
            if (
                set.has(arr[j].substr(0, k)) &&
                set.has(arr[j].substr(k, arr[j].length))
            ) {
                arr[j] = 1;
                break;
            }
        }
        arr[j] = arr[j] === 1 ? 1: 0;
    }

    print(arr.join(''));
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let n = readline();
        let strings = new Array();
        let dict = {};
        let result = new Array(n).fill(0);
        for (let i = 0; i < n; i++) {
            let str = readline();
            strings.push(str);
            if (dict[str]) {
                dict[str] = 2;
            } else {
                dict[str] = 1;
            }
        }

        wordLoop: for (let i = 0; i < n; i++) {
            lengthLoop: for (let len = 1; len < strings[i].length; len++) {
                let word = strings[i].substring(0, len);
                let suffix = strings[i].substring(len);
                if (word.length === strings[i].length / 2 && dict[word] === 2 && word === suffix) {
                    result[i] = '1';
                    continue wordLoop;
                }
                if (dict[word] === 1 && dict[suffix]) {
                    result[i] = '1';
                    continue wordLoop;
                } else {
                    continue lengthLoop;
                }
            }
            result[i] = '0';
        }

        output(result.join(''));
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let n = readline();
        let strings = new Array();
        let dict = {};
        let result = new Array(n).fill(0);
        for (let i = 0; i < n; i++) {
            let str = readline();
            strings.push(str);
            if (dict[str]) {
                dict[str] = 2;
            } else {
                dict[str] = 1;
            }
        }

        wordLoop: for (let i = 0; i < n; i++) {
            lengthLoop: for (let len = 1; len <= strings[i].length; len++) {
                let word = strings[i].substring(0, len);
                if (word.length === strings[i].length / 2 && dict[word] === 2) {
                    result[i] = '1';
                    continue wordLoop;
                }
                let suffix = strings[i].substring(len);
                if (dict[word] === 1 && dict[suffix]) {
                    result[i] = '1';
                    continue wordLoop;
                } else {
                    continue lengthLoop;
                }
            }
            result[i] = '0';
        }

        output(result.join(''));
    }
}

// // cat .\input.txt | node .\script.js
'use strict';
const util = require('util')
let data = ''; // raw
let inputs = ''; // iterator
function read() {
    let value = inputs.next().value.trim();
    return value
};
async function solve() {
    try {
        let n = parseInt(await read())
        let s = new Array(n)
        let mp = new Map()
        for (let i = 0; i < n; i++) {
            s[i] = await read()
            mp.set(s[i], true)
        }
        for (let i = 0; i < n; i++) {
            let ok = false
            for (let j = 1; j < s[i].length; j++) {
                let pref = s[i].substring(0, j)
                let suff = s[i].substring(j, s[i].length - j)
                if (mp.get(pref) && mp.get(suff)) {
                    ok = true
                }
            }
            process.stdout.write(ok == true ? '1' : '0');
        }
        process.stdout.write('\n');
    } catch (error) {
        console.log(error);
    }
}

async function main() {
    let tt = parseInt(await read())
    for (let i = 0; i < tt; i++) {
        await solve()
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => data += input);
process.stdin.on('end', async () => {
    let splitted = data.split('\r\n')
    inputs = await splitted.values();
    await main();
});

// https://stackoverflow.com/questions/20086849/how-to-read-from-stdin-line-by-line-in-node
// // cat .\input.txt | node .\script.js
'use strict';
const util = require('util')
let data = ''; // raw
let inputs = ''; // iterator
function read() {
    return inputs.next().value.trim();
};
async function main(read) {
    try {
        let tasks = parseInt(await read())
        let result = []
        for (let i = 0; i < tasks; i++) {
            const sub_length = parseInt(await read())
            result[i] = [new Array(sub_length).fill(0)]
            for (let j = 0; j < sub_length; j++) {
                const element = (await read());
                result[i] = [...result[i], element]
            }
        }
        for (let i = 0; i < result.length; i++) {
            const element_i = result[i];
            for (let j = 1; j < element_i.length; j++) {
                let element_j = element_i[j];
                // console.log(element_j)
                for (let k = 1; k < element_i.length; k++) {
                    if (j == k) continue
                    let element_k = element_i[k];
                    if (element_j.includes(element_k)) {
                        // console.log(element_j, ' << ', element_k)
                        element_j = element_j.replace(element_k, '')
                        --k
                    }
                    if (element_j.length == 0) result[i][0][j - 1] = 1
                }
            }
        }
        return result.map(e => e[0].join('')).join('\n')
    } catch (error) {
        console.log(error);
    }
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => data += input);
process.stdin.on('end', async () => {
    inputs = data.split('\n').values();
    const result = await main(read);
    // console.log(util.inspect(result, { showHidden: false, depth: null, colors: true }))
    // console.log(result)
    process.stdout.write(result);
});

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
// console.log(input)
var T = readline();
// var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
  var n = readline()//.split(' ').map((x) => parseInt(x));
  // var a = readline().split(' ').map((x) => parseInt(x));
  var mp = new Map();
  var ans = "";
  var s = []
  for(var i=0;i<n;i++) {
    var a = readline();
    mp.set(a, 0)
    s.push(a);
  }
  // if(tc==1)console.log(s)
  if(tc==1) console.log(mp)
  for(var i=0;i<n;i++) {
    var ok = false;
    // if(tc==1)console.log(s[i])
    for(var j=0;j<s[i].length;j++) {
      var f = s[i].slice(0, j+1);
      var se = s[i].slice(j+1, s[i].length);
      // if(tc == 1) console.log([f,se,j]);
      if(mp.has(se) && mp.has(f)) {
        ans += 1;
        ok = true;
        break;
      }
    }
    if(!ok) ans += 0;
  }
  console.log(ans)
}


var n = Number(readline());
var newStr = [];
for (var i = 0; i < n; i++){
    if(checkPalindrome('a', i))
        newStr[i] = 'b';
    else
        newStr[i] = 'a';
}

print(newStr.join(''));

function checkPalindrome(letter, size){
    if (size < 2)
        return false;

    return (letter == newStr[size - 2]);
}

  var n = parseInt(readline());
  var res = [];
  for(var i = 0; i < n; i += 4) {
    res.push('a', 'a', 'b', 'b');
  }
  res.length = n;
  print(res.join(''));

  var n = parseInt(readline());
  var res = [];
  for(var i = 0; i < n; i += 5) {
    res.push('a', 'a', 'b', 'b');
  }
  res.length = n;
  print(res.join(''));

  var n = parseInt(readline());
  var res = [];
  for(var i = 0; i < n; i += 5) {
    res.push('a', 'a', 'b', 'b', 'c');
  }
  res.length = n;
  print(res.join(''));

  var n = parseInt(readline());
  var res = '';
  for(var i = 5; i < n; i += 5) {
    res += 'aabbc';
  }
  res += 'aabbc'.substr(0, (n - res.length));
  print(res);