class CustomSumCalculator:
def __init__(self):
self.result_list = []
def custom_sum(self, nums, n, total):
if n == 0:
return total
last_value = nums.pop()
return self.custom_sum(nums, n - 1, total + (last_value ** 2) * (last_value > 0))
def process_and_store_results(self, num_tests):
if num_tests > 0:
try:
num_values = int(input())
values_list = list(map(int, input().split()))
result = self.custom_sum(values_list, num_values, 0)
self.result_list.append(result)
self.process_and_store_results(num_tests - 1)
except ValueError as error:
print(f"Error: {error}")
def display_results(self, idx=0):
if idx < len(self.result_list):
print(self.result_list[idx])
self.display_results(idx + 1)
def main():
try:
num_tests = int(input())
calculator = CustomSumCalculator()
calculator.process_and_store_results(num_tests)
calculator.display_results()
except ValueError as error:
print(f"Error: {error}")
except KeyboardInterrupt:
print("\nOperation interrupted by the user.")
if __name__ == "__main__":
main()