Help me in solving AO14 problem

My issue

Sample test case is passed but still Status is : Time Limit Exceeded
This is the code :

t=int(input())
for s in range(t):
n=int(input())
x=list(map(int,input().split()))
y =
i=0
res=
while i<n:
a=x[-1]
y.append(a)
y.extend(x)
y.pop()
res.append(y[0]+y[-1])
x=y
y=
i+=1
print(max(res))

Sample Input

3
2
5 8
3
5 10 15
4
4 4 4 4

Your Output

13
25
8

My code

t=int(input())
for s in range(t):
    n=int(input())
    x=list(map(int,input().split()))
    y = []
    i=0
    res=[]
    while i<n:
       a=x[-1]
       y.append(a)
       y.extend(x)
       y.pop()
       res.append(y[0]+y[-1])
       x=y
       y=[]
       i+=1
    print(max(res))




Learning course: Solve Programming problems using Python
Problem Link: Debug this code - First and Last Practice Problem in Solve Programming problems using Python - CodeChef

@sah76465rohit
plzz refer the following code

# Solution as follows

t=int(input())
for _ in range(t):
    n=int(input())
    arr=list(map(int, input().split()))
    temp=0
    #The initialisation value for this variable was incorrect. Can you think of why?
    final=arr[0]+arr[n-1]
    i=0
    while i<(n-1):
        temp=arr[i]+arr[i+1]
        if temp>final:
            final=temp
        i=i+1
    print(final)