from functools import reduce
import sys
def parse_int_list(numbers_str, acc=None):
if acc is None:
acc = []
# empty string case
numbers_str = numbers_str.strip()
if not numbers_str:
return acc
# Finding first number
space_index = numbers_str.find(' ')
if space_index == -1:
# returning Last number
return acc + [int(numbers_str)]
# recursive calling
current = int(numbers_str[:space_index])
return parse_int_list(numbers_str[space_index:], acc + [current])
def read_input():
return sys.stdin.readline().strip()
def process_test_case():
count = int(read_input())
numbers = parse_int_list(read_input())
# Filtering positive numbers and using reduce for calculating sum
return reduce(
lambda acc, x: acc + x * x,
filter(lambda x: x > 0, numbers),
0
)
def process_all_cases(remaining, results):
if remaining == 0:
# Printing all results without blank spaces
print(*results, sep='\n')
return
# Processing current test case and iterating rest
return process_all_cases(
remaining - 1,
results + [process_test_case()]
)
def main():
# Reading number of test cases
num_cases = int(read_input())
process_all_cases(num_cases, [])
if __name__ == "__main__":
main()
ZnJvbSBmdW5jdG9vbHMgaW1wb3J0IHJlZHVjZQppbXBvcnQgc3lzCgpkZWYgcGFyc2VfaW50X2xpc3QobnVtYmVyc19zdHIsIGFjYz1Ob25lKToKICAgIAogICAgaWYgYWNjIGlzIE5vbmU6CiAgICAgICAgYWNjID0gW10KICAgIAogICAgIyBlbXB0eSBzdHJpbmcgY2FzZQogICAgbnVtYmVyc19zdHIgPSBudW1iZXJzX3N0ci5zdHJpcCgpCiAgICBpZiBub3QgbnVtYmVyc19zdHI6CiAgICAgICAgcmV0dXJuIGFjYwogICAgCiAgICAjIEZpbmRpbmcgIGZpcnN0IG51bWJlcgogICAgc3BhY2VfaW5kZXggPSBudW1iZXJzX3N0ci5maW5kKCcgJykKICAgIGlmIHNwYWNlX2luZGV4ID09IC0xOgogICAgICAgICMgcmV0dXJuaW5nIExhc3QgbnVtYmVyCiAgICAgICAgcmV0dXJuIGFjYyArIFtpbnQobnVtYmVyc19zdHIpXQogICAgCiAgICAjIHJlY3Vyc2l2ZSBjYWxsaW5nCiAgICBjdXJyZW50ID0gaW50KG51bWJlcnNfc3RyWz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