Nikolay lives in a two-storied house. There are $n$ rooms on each floor, arranged in a row and numbered from one from left to right. So each room can be represented by the number of the floor and the number of the room on this floor (room number is an integer between $1$ and $n$). 

If Nikolay is currently in some room, he can move to any of the neighbouring rooms (if they exist). Rooms with numbers $i$ and $i+1$ on each floor are neighbouring, for all $1 \leq i \leq n - 1$. There may also be staircases that connect two rooms from different floors having the same numbers. If there is a staircase connecting the room $x$ on the first floor and the room $x$ on the second floor, then Nikolay can use it to move from one room to another.

 $\text{floor}$  The picture illustrates a house with $n = 4$. There is a staircase between the room $2$ on the first floor and the room $2$ on the second floor, and another staircase between the room $4$ on the first floor and the room $4$ on the second floor. The arrows denote possible directions in which Nikolay can move. The picture corresponds to the string "0101" in the input. 

 

Nikolay wants to move through some rooms in his house. To do this, he firstly chooses any room where he starts. Then Nikolay moves between rooms according to the aforementioned rules. Nikolay never visits the same room twice (he won't enter a room where he has already been). 

Calculate the maximum number of rooms Nikolay can visit during his tour, if:

  he can start in any room on any floor of his choice,  and he won't visit the same room twice. 


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 100$) — the number of test cases in the input. Then test cases follow. Each test case consists of two lines.

The first line contains one integer $n$ $(1 \le n \le 1\,000)$ — the number of rooms on each floor.

The second line contains one string consisting of $n$ characters, each character is either a '0' or a '1'. If the $i$-th character is a '1', then there is a staircase between the room $i$ on the first floor and the room $i$ on the second floor. If the $i$-th character is a '0', then there is no staircase between the room $i$ on the first floor and the room $i$ on the second floor.

In hacks it is allowed to use only one test case in the input, so $t = 1$ should be satisfied.


-----Output-----

For each test case print one integer — the maximum number of rooms Nikolay can visit during his tour, if he can start in any room on any floor, and he won't visit the same room twice.


-----Example-----
Input
4
5
00100
8
00000000
5
11111
3
110

Output
6
8
10
6



-----Note-----

In the first test case Nikolay may start in the first room of the first floor. Then he moves to the second room on the first floor, and then — to the third room on the first floor. Then he uses a staircase to get to the third room on the second floor. Then he goes to the fourth room on the second floor, and then — to the fifth room on the second floor. So, Nikolay visits $6$ rooms.

There are no staircases in the second test case, so Nikolay can only visit all rooms on the same floor (if he starts in the leftmost or in the rightmost room).

In the third test case it is possible to visit all rooms: first floor, first room $\rightarrow$ second floor, first room $\rightarrow$ second floor, second room $\rightarrow$ first floor, second room $\rightarrow$ first floor, third room $\rightarrow$ second floor, third room $\rightarrow$ second floor, fourth room $\rightarrow$ first floor, fourth room $\rightarrow$ first floor, fifth room $\rightarrow$ second floor, fifth room.

In the fourth test case it is also possible to visit all rooms: second floor, third room $\rightarrow$ second floor, second room $\rightarrow$ second floor, first room $\rightarrow$ first floor, first room $\rightarrow$ first floor, second room $\rightarrow$ first floor, third room.

Difficulty: EASY

Solutions:
t = int(input())
for i in range(0, t):
	n = int(input())
	s = input()
	a = 0
	aa = 0
	b = 0
	c = 0
	for j in s:
		a = a + 1
		if j == '1' and b == 0:
			b = a
		if j == '1':
			c = a
	if b != 0:
		b = n - b + 1
	for j in s:
		aa = aa + 1
		if j == 1:
			aa = aa + 1
	if b * 2 > c * 2:
		if b * 2 > aa:
			print(b * 2)
		else:
			print(aa)
	elif c * 2 > aa:
		print(c * 2)
	else:
		print(aa)


for t in range(int(input())):
	n = int(input())
	st = input()
	ans = n
	if '1' in st:
		ans = max(ans, (n - st.find('1')) * 2, (st.rfind('1') + 1) * 2)
		ans = max(ans, n + st.count('1'))
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	start = -1
	end = -1
	i = 0
	for c in s:
		if c == '1' and start == -1:
			start = i
		if c == '1':
			end = i + 1
		i += 1
	if start == -1:
		print(n)
	else:
		start = n - start
		if start > end:
			print(start * 2)
		else:
			print(end * 2)


import sys
from collections import defaultdict
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	s = sys.stdin.readline()[:-1]
	ans = 1
	for i in range(n):
		if s[i] == '1':
			ans = max(ans, (i + 1) * 2, (n - i) * 2)
		else:
			ans = max(ans, i + 1)
	print(ans)


t = int(input())
for _ in range(t):
	(n, s) = (int(input()), input())
	m = 0
	for i in range(n):
		if s[i] == '1':
			k = max(i + 1, n - i)
			if k > m:
				m = k
	if m:
		print(m * 2)
	else:
		print(n)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	length = len(s)
	count = length
	trigger = False
	for (front, back) in zip(s, s[::-1]):
		if front == '1' or back == '1':
			trigger = True
			break
		count -= 1
	if not trigger:
		print(length)
	else:
		print(count * 2)


I = input
for _ in [0] * int(I()):
	I()
	s = I()
	print(2 * max(len(s.lstrip('0')), len(s.rstrip('0'))) or len(s))


t = input()
for i in range(int(t)):
	n = input()
	max = int(n)
	str0 = input()
	for j in range(int(n)):
		if str0[j] == '1':
			if 2 * j > int(n) - 1:
				s = j + 1
			else:
				s = int(n) - j
				j = s
			if 2 * s > max:
				max = 2 * s
	print(max)


for _ in range(int(input())):
	n = int(input())
	rooms = list(map(int, list(input())))
	no1 = sum(rooms)
	if no1 == 0:
		print(n)
		continue
	if no1 == 1:
		ind = rooms.index(1)
		if n % 2 == 1 and ind == n // 2:
			print(2 * (ind + 1))
		elif ind < n // 2:
			print(2 * (n - ind))
		else:
			print(2 * (ind + 1))
		continue
	for i in range(n):
		if rooms[i]:
			start = i
			break
	for i in range(n - 1, -1, -1):
		if rooms[i]:
			end = i
			break
	if start == 0 or end == n - 1:
		print(2 * n)
	elif start + 1 > n - end:
		print(2 * (end + 1))
	else:
		print(2 * (n - start))


def solve(n, s):
	ans = n
	for i in range(len(s)):
		if s[i] == '1':
			ans = max(ans, 2 + i + max(i, n - i - 1))
	s = s[::-1]
	for i in range(n):
		if s[i] == '1':
			ans = max(ans, 2 + i + max(i, n - i - 1))
	print(ans)
for t in range(int(input())):
	n = int(input())
	s = input()
	solve(n, s)


a = []
for tc in [0] * int(input()):
	n = int(input())
	s = input()
	d = min(s[::-1].find('1'), s.find('1'))
	if d != -1:
		print(2 * n - 2 * d)
	else:
		print(n)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input()]
	c = 0
	flag = False
	ind1 = None
	ind2 = None
	for i in range(n):
		if a[i] == 1 and flag is False:
			ind1 = i
			flag = True
		elif a[i] == 1:
			ind2 = i
	if ind1 is not None and ind2 is not None:
		res = 2 * (n - min(ind1 - 0, n - 1 - ind2))
	elif ind1 is not None:
		res = 2 * (n - min(ind1 - 0, n - 1 - ind1))
	elif ind2 is not None:
		res = 2 * (n - min(ind2, n - 1 - ind2))
	else:
		res = n
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ans = n
	if '1' in s and s.index('1') < s[::-1].index('1'):
		s = s[::-1]
	for i in range(n):
		if s[i] == '1':
			tmp = i + 1 + max(i, n - i - 1) + 1
			ans = max(ans, tmp)
		else:
			continue
	print(ans)


for t in range(int(input())):
	n = int(input())
	s = input()
	l = s.find('1')
	if l == -1:
		print(n)
		continue
	r = s[::-1].find('1')
	print(2 * n - 2 * min(l, r))


import sys

def ints():
	return list(map(int, sys.stdin.readline().strip().split()))
tc = int(input())
while tc:
	tc -= 1
	n = int(input())
	s = input()
	t = s[::-1]
	if s.count('1') == 0:
		print(n)
		continue
	ans = max(2 * (n - t.index('1')), 2 * (n - s.index('1')))
	ans = max(ans, s.index('1') + 2 * s.count('1') + t.index('1'))
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = input()
	x = -1
	y = -1
	for i in range(len(arr)):
		if arr[i] == '1':
			x = i
			break
	arr = arr[::-1]
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] == '1':
			y = i
	if x == -1:
		print(n)
		continue
	print(max(x + 1, n - x, n - y, y + 1) * 2)


a = int(input())
for i in range(a):
	b = int(input())
	c = input()
	max = b * 2
	i = 0
	j = len(c) - 1
	if '1' in c:
		if c[i] == '1' or c[j] == '1':
			max = b * 2
		while c[i] != '1' and c[j] != '1' and (i <= j):
			i += 1
			j -= 1
			max -= 2
	else:
		max = b
	print(max)


for _ in range(int(input())):
	n = int(input())
	s = input()
	maxi = n
	for i in range(n):
		if s[i] == '1':
			maxi = max(maxi, max(2 * (i + 1), 2 * (n - i)))
	print(maxi)


for i in range(int(input())):
	n = int(input())
	stairCase = input()
	if '1' not in stairCase:
		print(n)
	else:
		index = min(1 + stairCase.find('1'), n - stairCase.rfind('1'))
		print(2 * max(index, n - index + 1))


import math
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def intin():
	s = input()
	return list(map(int, s[:len(s) - 1]))
t = inp()
while t > 0:
	t -= 1
	l = inp()
	n = intin()
	if not 0 in n:
		print(l * 2)
		continue
	if not 1 in n:
		print(l)
		continue
	s = [0]
	i = 0
	for e in n:
		if e == 0:
			i += 1
		else:
			break
	d = 0
	for e in n[::-1]:
		if e == 0:
			d += 1
		else:
			break
	print((l - (d if d < i else i)) * 2)


testCase = int(input())
for i in range(testCase):
	size = int(input())
	stairs = str(input())
	first = -1
	last = -1
	for i in range(size):
		if stairs[i] == '1':
			first = i
			break
	for i in range(size - 1, -1, -1):
		if stairs[i] == '1':
			last = i
			break
	if first != -1 and last != -1:
		maxDist = max(last + 1, size - first)
		print(maxDist * 2)
	else:
		print(size)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	f = a.find('1')
	if f == -1:
		print(n)
	else:
		print(2 * max(n - f, a.rfind('1') + 1))


t = int(input())
for _ in range(t):
	(n, s, res1, res2) = (int(input()), input(), 0, 0)
	x = s.count('1')
	if x > 1:
		(a, b) = (s.find('1'), s.rfind('1'))
		print(max(2 * (b + 1), 2 * (n - a)))
	elif x == 1:
		a = s.find('1')
		print(max((a + 1) * 2, 2 * (n - a)))
	else:
		print(n)


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	N = int(input())
	S = list(input().rstrip())
	Query.append((N, S))
for (N, S) in Query:
	P = []
	for (i, s) in enumerate(S):
		if s == '1':
			P.append(i)
	L = len(P)
	if L == 0:
		print(N)
	else:
		n1 = P[0] + 1
		n2 = P[-1] + 1
		ans = max([n2 * 2, (N - n1 + 1) * 2, N + 1])
		print(ans)


def solve(s, n):
	ans = n
	first = -1
	for i in range(n):
		if s[i] == '1':
			first = i
			break
	if first != -1:
		ans = max(ans, 2 * (n - first))
	second = -1
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			second = i
			break
	if second != -1:
		ans = max(ans, 2 * (second + 1))
	print(ans)

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		s = input()
		solve(s, n)
main()


for _ in range(int(input())):
	n = int(input())
	str = input()
	if int(str) == 0:
		print(n)
	else:
		for i in range(len(str)):
			if str[i] == '1':
				s1 = i + 1
				break
		for j in range(len(str) - 1, -1, -1):
			if str[j] == '1':
				s2 = j + 1
				break
		a1 = max(2 * s1, 2 * (n - s1 + 1))
		a2 = max(2 * s2, 2 * (n - s2 + 1))
		print(max(a1, a2))


for _ in range(int(input())):
	n = int(input())
	s = input()
	fs = s.find('1')
	ans = (n - fs) * 2
	sc = s.rfind('1')
	ans = max((sc + 1) * 2, ans)
	print(ans if fs != -1 else n)


for _ in range(int(input())):
	n = int(input())
	s = input()
	li = s.find('1')
	ri = s.rfind('1')
	m = n // 2
	if li == -1:
		print(n)
	else:
		if n % 2 != 0:
			a = max(abs(m - li), abs(m - ri)) + m + 1
		else:
			x = abs(m - 1 - li) if li <= m - 1 else abs(m - li)
			y = abs(m - 1 - ri) if ri <= m - 1 else abs(m - ri)
			a = max(x, y) + m + 1
		print(a * 2)


import math
am = int(input())
for i in range(am):
	rooms = int(input())
	ladders = input()
	if '1' in ladders:
		ind = int(ladders.find('1'))
		rind = int(ladders.rfind('1')) + 1
		print(max(rind * 2, (rooms - ind) * 2))
	else:
		print(rooms)


for i in range(int(input())):
	n = int(input())
	s = input()
	M = 0
	for j in range(n):
		if s[j] == '1':
			M = max(M, (n - j) * 2)
			M = max(M, j * 2 + 2)
	print(max(M, n))


q = int(input())
for i in range(q):
	n = int(input())
	t = input()
	if '1' in t:
		l1 = t.index('1')
		l2 = t[::-1].index('1')
		print(2 * max(n - l1 - 1, l1, n - l2 - 1, l2) + 2)
	else:
		print(n)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(input())
	c = 0
	v = []
	for i in range(n):
		if l[i] == '1':
			c += 1
			v.append(i)
	if c == 0:
		print(n)
	else:
		print(max(2 * (n - int(v[0])), 2 * (int(v[len(v) - 1]) + 1)))


t = int(input())
i = 0
while i < t:
	n = int(input())
	mass = str(input())
	numbers = []
	numb1 = []
	numb2 = []
	ind = 0
	while ind < n:
		numbers.insert(0, int(mass[ind]))
		ind += 1
	if 1 in numbers:
		end = int(len(numbers) / 2)
		for e in numbers[:end]:
			numb1.append(e)
		for e in numbers[end:]:
			numb2.insert(0, e)
		indNUMB1 = 0
		indNUMB2 = 0
		min = 1001
		for e in numb1:
			if e == 1 and indNUMB1 < min:
				min = indNUMB1
			indNUMB1 += 1
		for e in numb2:
			if e == 1 and indNUMB2 < min:
				min = indNUMB2
			indNUMB2 += 1
		answer = (n - min) * 2
		print(answer)
	else:
		print(n)
	i += 1


import sys

def rint():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().rstrip('\n')

def oint():
	return int(input())
t = oint()
for _ in range(t):
	n = oint()
	s = input()
	mini = n
	maxi = -1
	for i in range(n):
		if s[i] == '1':
			mini = min(mini, i)
			maxi = max(maxi, i)
	ii = max(n - mini, maxi + 1)
	print(max(2 * ii, n))


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	f = s.find('1')
	l = s.rfind('1')
	if f == -1:
		print(n)
		continue
	print(2 * (n - min(f, n - (l + 1))))


case = int(input())
for c in range(case):
	l = int(input())
	s = input()
	graph = [[] for _ in range(2)]
	visited = [[] for _ in range(2)]
	first = -1
	last = -1
	for i in range(l):
		graph[0].append(0 if s[i] == '0' else 1)
		graph[1].append(0 if s[i] == '0' else 1)
		visited[0].append(False)
		visited[1].append(False)
		if s[i] == '1' and first == -1:
			first = i
		if s[i] == '1' and i > last:
			last = i
	maximum = 0
	count = 0
	for i in range(l):
		if i <= last:
			count += 1
		else:
			break
	if first != -1:
		count += max(l - last - 1, last + 1)
	maximum = max(maximum, count)
	count = 0
	for i in range(l - 1, -1, -1):
		if i >= first:
			count += 1
		else:
			break
	if last != -1:
		count += max(first + 1, l - first)
	maximum = max(maximum, count)
	print(maximum)


q = int(input())
for _ in range(q):
	n = int(input())
	string = input()
	if string.count('1') == 0:
		print(n)
	else:
		temp = string[::-1]
		ind1 = string.find('1')
		ind2 = temp.find('1')
		ans = max(n - ind1, n - ind2)
		print(2 * ans)


t = int(input())
outputs = []
for i in range(t):
	n = int(input())
	s = input()
	if s.find('1') != -1:
		pos = min(s.find('1'), n - 1 - s.rfind('1'))
		outputs.append((n - pos) * 2)
	else:
		outputs.append(n)
for i in outputs:
	print(i)


p = int(input())
for i in range(p):
	room = int(input())
	stair = list(input())
	if '1' not in stair:
		num = room
	else:
		a = stair.index('1')
		b = list(reversed(stair)).index('1')
		if room - a > room - b:
			num = (room - a) * 2
		else:
			num = (room - b) * 2
	print(str(num))


def main():
	n = int(input())
	string = str(input())
	index = -1
	last = -1
	for i in range(n):
		if string[i] == '1':
			index = i
			break
	for j in range(n - 1, -1, -1):
		if string[j] == '1':
			last = j
			break
	if index == 0 or last == n - 1:
		print(2 * n)
	elif index != -1:
		print(max(n - 1 - index + 1, index + 1, last + 1, n - 1 - index + 1) * 2)
	else:
		print(n)

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


for _ in range(int(input())):
	input()
	s = input()
	ones_counter = 0
	first_one = None
	last_one = 0
	for (i, c) in enumerate(s):
		if c == '1':
			if first_one is None:
				first_one = i
			last_one = i
			ones_counter += 1
	if ones_counter == 0:
		print(len(s))
	else:
		print(2 * max(len(s) - first_one, last_one + 1))


t = int(input())
while t > 0:
	n = int(input())
	l = [int(i) for i in input()]
	if l[0] == 1 or l[n - 1] == 1:
		print(2 * n)
	elif l.count(0) == n:
		print(n)
	else:
		sol = []
		for i in range(len(l)):
			if l[i] == 1:
				sol.append(max(max(n + 1, 2 * (i + 1)), 2 * (n - i)))
		print(max(sol))
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	x = [i for i in range(n) if s[i] == '1']
	if len(x) == 0:
		print(n)
	else:
		print(max((max(i + 1 + i + 1, n - i + n - i) for i in x)))


t = int(input())
for i in range(t):
	n = int(input())
	l = input()
	l = list(l)
	f = []
	if l.count('1') == 0:
		print(n)
	elif l.count('1') > 0:
		if l[0] == '1':
			print(2 * n)
		elif l[n - 1] == '1':
			print(2 * n)
		else:
			for j in range(n):
				if l[j] == '0':
					continue
				elif l[j] == '1':
					b1 = (n - j) * 2
					break
			l = l[::-1]
			for j in range(n):
				if l[j] == '0':
					continue
				elif l[j] == '1':
					b2 = (n - j) * 2
					break
			print(max(b1, b2))


T = int(input())
for _ in range(T):
	N = int(input())
	stair = [x == '1' for x in input()]
	try:
		first_stair = stair.index(True)
		last_stair = N - stair[::-1].index(True) - 1
	except:
		print(N)
		continue
	if first_stair == -1:
		print(N)
		continue
	max_dist = N
	max_dist = max(max_dist, 2 * (last_stair + 1), 2 * (N - first_stair))
	max_dist = max(max_dist, N + len(list(filter(lambda x: x == True, stair))))
	print(max_dist)


for i in range(int(input())):
	n = int(input())
	s = input()
	if '1' in s:
		b = s.index('1') + 1
		q = n - b + 1
		s = s[::-1]
		l = s.index('1') + 1
		e = n - l + 1
		print(2 * max(b, q, l, e))
	else:
		print(n)


for _ in range(int(input())):
	n = int(input())
	a = input()
	f = 10001
	m = 0
	if '1' not in a:
		print(n)
	else:
		for i in range(n):
			if a[i] == '1':
				f = min(i, f)
				m = max(i, m)
		print((n - f) * 2 if n - f > m else (m + 1) * 2)


for _ in range(int(input())):
	n = int(input())
	a = input()
	c = a.count('1')
	if c == 0:
		print(n)
	else:
		print(2 * (n - min(a.find('1'), n - a.rfind('1') - 1)))


for _ in range(int(input())):
	n = int(input())
	res = n
	cur = 0
	for (i, c) in enumerate(input()):
		if c == '1':
			x = i + 1
			y = n - x + 1
			res = max(res, 2 * x, n + 1, 2 * y)
			cur += 2
		else:
			cur += 1
	print(max(cur, res))


t = int(input())
result = []
for _ in range(t):
	n = int(input())
	ways = list(input())
	if '1' in ways:
		idx1 = ways.index('1')
		idx2 = ways[::-1].index('1')
		out = 2 * (n - min(idx1, idx2))
	else:
		out = n
	result.append(out)
for i in range(t):
	print(result[i])


t = int(input())
for tt in range(t):
	n = int(input())
	s = input()
	if '1' not in s:
		print(n)
	else:
		left = 0
		right = n - 1
		i = 0
		while i < n and s[i] == '0':
			i += 1
		left = i
		i = n - 1
		while i >= 0 and s[i] == '0':
			i -= 1
		right = i
		print(max((n - left) * 2, (right + 1) * 2))


for _ in range(int(input())):
	n = int(input())
	s = input()
	if '1' not in s:
		print(n)
		continue
	(x, y) = ((s.rfind('1') + 1) * 2, (s[::-1].rfind('1') + 1) * 2)
	print(max(x, y))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	i1 = -1
	i2 = -1
	j = 0
	i1 = s.find('1')
	s = s[::-1]
	i2 = s.find('1')
	if i1 == -1:
		print(n)
	else:
		print((n - min(i1, i2)) * 2)


t = int(input())
import math
for i in range(t):
	n = int(input())
	s = input()
	a = s.find('1')
	b = s[-1::-1].find('1')
	if a == -1:
		print(len(s))
	else:
		print(2 * max(len(s) - a, len(s) - b))


import math

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		s = str(input())
		q = n
		minI = math.inf
		maxI = 0
		for c in range(len(s)):
			if s[c] == '1':
				q += 1
				minI = min(minI, c + 1)
				maxI = max(maxI, c + 1)
		q = max(q, (n - minI + 1) * 2)
		q = max(q, (maxI - 1 + 1) * 2)
		print(q)
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	try:
		print(2 * max(n - s.index('1'), n - s[::-1].index('1')))
	except:
		print(n)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	pos = [ind for (ind, c) in enumerate(s) if c == '1']
	res = n
	for x in pos:
		res = max(res, 2 * max(x + 1, n - x))
	print(res)


t = int(input())
for j in range(t):
	n = int(input())
	s = input()
	l = 0
	r = 0
	for i in range(0, n):
		if s[i:i + 1] == '1':
			l = i + 1
	for i in range(n - 1, -1, -1):
		if s[i:i + 1] == '1':
			r = n - i
	print(max(max(2 * l, 2 * r), n))


t = int(input())
p = 0
for i in range(1, t + 1):
	n = int(input())
	c = str(input())
	a = list(c)
	b = []
	if a[0] == '1' or a[n - 1] == '1':
		print(n * 2)
	elif '1' not in a:
		print(len(c))
	else:
		b = [j for (j, value) in enumerate(a) if value == '1']
		c = max(b)
		d = n - 1 - min(b)
		if c >= d:
			print(2 * (c + 1))
		else:
			print(2 * (d + 1))


for rpt in range(int(input())):
	n = int(input())
	layout = input()
	if layout == n * '0':
		print(n)
	else:
		left = 0
		while layout[left] == '0':
			left += 1
		right = n - 1
		while layout[right] == '0':
			right -= 1
		print(2 * max(n - left, right + 1))


import math
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	j = 0
	while j < math.ceil(n / 2) and s[j] != '1' and (s[n - j - 1] != '1'):
		j += 1
	if j == math.ceil(n / 2):
		print(n)
	else:
		print((n - j) * 2)


l = int(input())
for i in range(l):
	n = int(input())
	li1 = input()
	li = []
	for i in range(n):
		li.append(int(li1[i]))
	if li[0] == 1 or li[-1] == 1:
		print(2 * n)
		continue
	cont = 1
	for i in range(1, n):
		if li[i] == 1:
			li[i] = cont
			cont += 1
	if 1 not in li:
		print(n)
		continue
	idx1 = li.index(1)
	idx2 = li.index(max(li))
	pos1 = idx1
	pos2 = n - 1 - idx2
	if pos1 > pos2:
		print(2 * (1 + idx2))
	else:
		print(2 * (n - idx1))


t = int(input())
for i in range(t):
	k = int(input())
	a = input()
	if int(a[0]) == 1 or int(a[len(a) - 1]) == 1:
		print(2 * len(a))
	else:
		j = 0
		while j < len(a) and int(a[j]) != 1:
			j += 1
		j1 = j
		j = len(a) - 1
		while j >= 0 and int(a[j]) != 1:
			j -= 1
		jn = j
		if j1 == len(a):
			print(len(a))
		elif jn == -1:
			print(len(a))
		else:
			j = max(len(a) - j1, jn + 1)
			print(j * 2)


from sys import stdin, stdout
import math
t = stdin.readline()
t = int(t)
for _ in range(t):
	n = int(stdin.readline())
	s = stdin.readline()
	ans = n
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			ans = (i + 1) * 2 if ans < (i + 1) * 2 else ans
			break
	s = s[::-1]
	for j in range(n, -1, -1):
		if s[j] == '1':
			ans = j * 2 if ans < j * 2 else ans
			break
	print(ans)


import math
t = int(input())
while t > 0:
	n = int(input())
	inp = list(map(int, list(input())))
	if inp[0] == 1 or inp[n - 1] == 1:
		print(n * 2)
	else:
		counter = 0
		for i in inp:
			if i == 0:
				counter = counter + 1
			else:
				counter = counter + 2
		startI = 0
		endI = 0
		for i in range(1, n):
			if inp[i] == 1:
				startI = i
				break
		for i in range(n - 1, 0, -1):
			if inp[i] == 1:
				endI = i
				break
		if startI != 0:
			t1 = (n - startI) * 2
		else:
			t1 = 0
		if endI != 0:
			t2 = (endI + 1) * 2
		else:
			t2 = 0
		print(max(counter, t1, t2))
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	if s == '0' * n:
		print(n)
	else:
		print(max(n - s.index('1'), s.rindex('1') + 1) * 2)


for _ in range(int(input())):
	n = int(input())
	s = str(input())
	x = 0
	y = 0
	for i in range(n):
		if s[i] == '1':
			a1 = i
			x = i + 1
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			a2 = i
			y = i + 1
			break
	if x == 0 and y == 0:
		print(n)
	else:
		p = max(2 * x, 2 * (n - x + 1))
		q = max(2 * y, 2 * (n - y + 1), n + 1)
		print(max(p, q))


def ans(n, s):
	r = -1
	l = -1
	for i in range(n):
		if s[i] == '1':
			l = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			r = i
			break
	out = 2 * max(r + 1, n - l)
	if r == -1:
		out = n
	return out
t = int(input())
while t > 0:
	n = int(input())
	s = input()
	print(ans(n, s))
	t -= 1


import sys
import math
input = sys.stdin.readline
T = int(input())
for i in range(0, T):
	n = int(input())
	string = input()
	leng = len(string)
	st = en = -1
	for i in range(0, leng):
		if string[i] == '1':
			if st == -1:
				st = en = i
			else:
				en = i
	if st == -1:
		print(n)
	else:
		shift = st
		if en != -1:
			shift = min(n - 1 - en, shift)
		print(max(n, (n - shift) * 2))


import math as mx
q = int(input())
for xta in range(q):
	tot = int(input())
	strx = input()
	ma = -1
	mb = -1
	for i in range(len(strx)):
		if strx[i] == '1' and ma == -1:
			ma = i
			mb = i
		elif strx[i] == '1':
			mb = i
	ma += 1
	mb += 1
	ans1 = 0
	ans2 = 0
	ansa = 0
	if ma != 0:
		ans1 = tot - ma + 1 + max(ma, tot - ma + 1)
	if mb != 0:
		ans2 = mb + max(mb, tot - mb + 1)
	ansa = max(ans1, ans2)
	if ansa == 0:
		ansa = tot
	print(ansa)


import os, sys, atexit
from io import BytesIO, StringIO
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	n = int(input())
	v = input().strip()
	ans = 0
	for (i, x) in enumerate(v):
		if x == '1':
			ans = max(ans, 2 * (i + 1), 2 * (n - i))
		else:
			ans = max(ans, i + 1)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	sr = s[::-1]
	for j in range(n):
		if s[j] == '1' or sr[j] == '1':
			print((n - j) * 2)
			break
	else:
		print(n)


from sys import stdin
from math import *
for i in range(int(input())):
	n = int(input())
	s = input()
	x = 0
	y = 0
	for j in range(n):
		if s[j] == '1':
			x = j
			y = 1
			break
	if y == 1:
		ans1 = 2 * (n - x)
	else:
		ans1 = n
	x = 0
	y = 0
	for j in range(1, n + 1):
		if s[-j] == '1':
			x = j - 1
			y = 1
			break
	if y == 1:
		ans2 = 2 * (n - x)
	else:
		ans2 = n
	print(max(ans1, ans2))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	mdist = 0
	if '1' in set(s):
		for j in range(1, n + 1):
			if s[j - 1] == '1':
				a = max(j, n - j + 1)
				if a > mdist:
					mdist = a
		print(mdist * 2)
	else:
		print(n)


for _ in range(int(input())):
	l = int(input())
	s = input()
	if '1' in s:
		print(2 * max(l - s.index('1'), l - s[::-1].index('1')))
	else:
		print(l)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if '1' not in s:
		print(n)
		continue
	print(max(n + s.count('1'), (s.rfind('1') + 1) * 2, (n - s.find('1')) * 2))


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	m = -1 if s.find('1') == -1 else min([s.index('1'), len(s) - 1 - s.rindex('1')])
	if m == -1:
		print(n)
	elif m == 0:
		print(2 * len(s))
	else:
		print(2 * len(s) - 2 * m)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	(l, r) = (n - s.find('1'), s.rfind('1') + 1)
	print(n if s.count('1') == 0 else max(l * 2, r * 2))


import math
t = int(input())
while t > 0:
	n = int(input()) - 1
	s = str(input())
	mx = int(-1)
	mn = int(n + 1)
	i = 0
	for _ in s:
		if s[i] == '1':
			mx = max(mx, i)
			mn = min(mn, i)
		i += 1
	temp = n + 1
	temp = max(temp, mn + (mx - mn + 1) * 2)
	temp = max(temp, n - mx + (mx - mn + 1) * 2)
	temp = max(temp, (mx + 1) * 2)
	temp = max(temp, (n - mn + 1) * 2)
	print(temp)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	mnj = s.find('1')
	mxj = s.rfind('1')
	if mnj == -1:
		print(n)
	else:
		print(max(n - mnj, mxj + 1) * 2)


t = int(input())
results = []
for _ in range(t):
	n = int(input())
	stairs = input()
	best = n
	left1 = -1
	right1 = -1
	for i in range(n):
		if stairs[i] == '1':
			if left1 == -1:
				left1 = i
			right1 = i
	if right1 != -1:
		best = n + 1
		best = max(best, 2 * (n - left1))
	if left1 != -1:
		best = max(best, 2 * (right1 + 1))
	results.append(best)
for i in results:
	print(i)


from math import ceil
t = int(input())
for test in range(t):
	n = int(input())
	rooms = [int(i) for i in input()]
	last_stair = -1
	for i in range(ceil(len(rooms) / 2)):
		if i + 1 > ceil(len(rooms) / 2):
			print(i, len(rooms))
			break
		if rooms[i] == 1 or rooms[-i - 1] == 1:
			last_stair = i
			break
	if last_stair == -1:
		print(n)
	else:
		print((n - last_stair) * 2)


for t in range(int(input())):
	n = int(input())
	a = input()
	if '1' in a:
		i1 = a.find('1')
		i2 = n - a.rfind('1') - 1
		k = 2 * n - 2 * min(i1, i2)
	else:
		k = n
	print(k)


for i in range(int(input())):
	n = int(input())
	s = input()
	if '1' not in s:
		print(n)
	else:
		i = s.find('1') + 1
		j = s.rfind('1') + 1
		a = max(2 * i, n + 1)
		b = max(2 * j, n + 1)
		c = max(a, b)
		s = s[::-1]
		i = s.find('1') + 1
		j = s.rfind('1') + 1
		a = max(2 * i, n + 1)
		b = max(2 * j, n + 1)
		d = max(a, b)
		print(max(c, d))


t = int(input())
for i in range(t):
	n = int(input())
	x = input()
	f = 0
	m = 0
	m1 = 0
	e = []
	for j in range(n - 1, -1, -1):
		if x[j] == '1':
			m = j + 1
			f = 1
			break
	for k in range(n):
		if x[k] == '1':
			m1 = n - k
			f = 1
			break
	if m > m1:
		max1 = m
	else:
		max1 = m1
	if f == 0:
		print(n)
	else:
		r = max1 * 2
		print(r)


t = int(input())
for i in range(t):
	n = int(input())
	str = input()
	stairs = []
	for i in range(len(str)):
		if str[i] == '1':
			stairs.append(i)
	if not stairs:
		print(n)
	else:
		stairs.sort()
		mx = max(stairs)
		mn = min(stairs)
		start = max(mx + 1, n - mn)
		gain = sum([x > start for x in stairs])
		print(start * 2 + gain)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	flag = 0
	mini = len(a) + 1
	maxi = -1
	for i in range(len(a)):
		if a[i] == '1':
			flag = 1
			if mini > i:
				mini = i
			if maxi < i:
				maxi = i
	mini = len(a) - mini - 1
	maxi = max(maxi, mini)
	if flag:
		print(2 * (maxi + 1))
	else:
		print(len(a))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	l = -1
	r = -1
	for j in range(len(s)):
		if l == -1 and s[j] == '1':
			l = j
		if s[j] == '1':
			r = j + 1
	if l == -1 or r == -1:
		print(n)
	else:
		l = n - l
		print(max(l, r) * 2)


for _ in range(int(input())):
	n = int(input())
	arr = [x for x in input()]
	if '1' in arr:
		farthest = closest = None
		for num in range(n - 1, -1, -1):
			if arr[num] == '1':
				farthest = num
				break
		for num in range(n):
			if arr[num] == '1':
				closest = num
				break
		print(max((farthest + 1) * 2, (n - closest) * 2))
	else:
		print(n)


def solve(s, n):
	one_ind = []
	for (i, c) in enumerate(s, start=1):
		if c == '1':
			one_ind.append(i)
	if len(one_ind) == 0:
		return n
	if len(one_ind) == 1:
		return max(n + 1, 2 * one_ind[0])
	return max(n + len(one_ind), 2 * one_ind[-1], one_ind[-2] + len(one_ind) - 1 + 2 * (one_ind[-1] - one_ind[-2]))
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	print(max(solve(s, n), solve(s[::-1], n)))


for case in range(int(input())):
	n = int(input())
	s = input()
	primeiro = -1
	ultimo = -1
	for c in range(len(s)):
		if s[c] == '1':
			primeiro = c
			break
	for c in range(len(s) - 1, -1, -1):
		if s[c] == '1':
			ultimo = c
			break
	if primeiro == -1:
		print(len(s))
	else:
		m = max(len(s) - primeiro, ultimo + 1)
		print(m * 2)


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	s = stdin.readline()[:-1]
	if '1' not in s:
		print(n)
	else:
		print(2 * max(n - s.find('1'), s.rfind('1') + 1))


t = int(input())
for i in range(t):
	n = int(input())
	s = str(input())
	di = 0
	db = 0
	for i in range(n):
		c = s[i]
		if c == '1':
			di = 2 * (n - i)
			break
	for i in range(n - 1, -1, -1):
		c = s[i]
		if c == '1':
			db = 2 * (i + 1)
			break
	if di == 0:
		print(n)
	else:
		print(max(di, db))


for _ in range(int(input())):
	n = int(input())
	s = input()
	fs = s.find('1')
	if fs == -1:
		print(n)
	elif s.count('1') == 1:
		ans = n + 1
		fp = s.find('1')
		ans = max(ans, 2 * (fp + 1))
		fp1 = fp
		fp = n - fp - 1
		ans = max(ans, 2 * (fp1 + 1))
		ans = max(ans, 2 * (fp + 1))
		ans = max(ans, 2 * (fs + 1))
		fs = n - fs - 1
		ans = max(ans, 2 * (fs + 1))
		print(ans)
	else:
		ans = n + 2
		s = s[::-1]
		fp = s.find('1')
		ans = max(ans, 2 * (fp + 1))
		fp1 = fp
		fp = n - fp - 1
		fa = fs
		ans = max(ans, 2 * (fp + 1))
		ans = max(ans, 2 * (fs + 1))
		fs = n - fs - 1
		ans = max(ans, 2 * (fs + 1))
		gap = abs(fp - fa) - 1
		ans = max(ans, fa + 1 + 1 + gap + 2 + gap)
		gap = abs(fp1 - fs) - 1
		ans = max(ans, fp1 + 2 + gap + 2 + gap)
		print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ans = n
	if '1' in s:
		ans = max(ans, 2 * (n - s.find('1')), 2 * (s.rfind('1') + 1))
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = input()
	if a.count('1') == 0:
		print(n)
	else:
		(x, y) = (a.index('1'), a[::-1].index('1'))
		print(2 * (n - min(x, y)))


cases = int(input())
res = []
while cases != 0:
	rooms = int(input())
	str1 = list(input())
	if not '1' in str1:
		res.append(rooms)
	else:
		res.append(2 * max(rooms - int(str1[::-1].index('1')), rooms - int(str1.index('1'))))
	cases -= 1
print(*res, sep='\n')


m = int(input())
for k in range(m):
	n = int(input())
	s = input()
	l_index = -1
	r_index = -1
	ans = -1
	for i in range(n):
		if s[i] == '1':
			l_index = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			r_index = i
			break
	if l_index == -1 or r_index == -1:
		if l_index == -1 and r_index == -1:
			print(n)
		else:
			print(max(2 * (l_index + 1), n, 2 * (n - l_index)))
	else:
		print(max(2 * (r_index + 1), n, 2 * (n - l_index)))


def answer():
	n = int(input())
	s = input()
	one_indexs = [i for (i, c) in enumerate(s) if '1' == c]
	len_one = len(one_indexs)
	if len_one == 0:
		return n
	elif len_one == 1:
		index_one = one_indexs[0]
		st = max(n - 1 - index_one + 1, index_one + 1)
		return 2 * st
	index_one1 = one_indexs[0]
	index_one2 = one_indexs[-1]
	st = max(n - 1 - index_one1 + 1, index_one2 + 1)
	return 2 * st
aa = int(input())
for _ in range(aa):
	out = answer()
	print(out)


t = [int(k) for k in input().split(' ')][0]
for nt in range(t):
	n = [int(k) for k in input().split(' ')][0]
	a = [int(k) for k in input()]
	mx = n
	for i in range(n):
		if a[i]:
			mx = max(mx, 2 * (i + 1), 2 * (n - i))
	print(mx)


n = int(input())
for bla in range(n):
	numberOfRooms = int(input())
	rooms = input()
	result = numberOfRooms
	for i in range(numberOfRooms):
		start = rooms[i]
		end = rooms[numberOfRooms - i - 1]
		if start == '1' or end == '1':
			result = max(result, (numberOfRooms - i) * 2)
			break
	print(result)


import sys
t = int(input())
for i in range(t):
	n = int(input())
	s = input().rstrip()
	max_id = None
	min_id = None
	for (i, ch) in enumerate(s):
		if ch == '1':
			min_id = i
			break
	for (i, ch) in enumerate(s[::-1]):
		if ch == '1':
			max_id = i
			break
	if max_id == None:
		print(n)
	else:
		print(2 * n - min(max_id, min_id) * 2)


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	st = n
	end = -1
	for i in range(len(s)):
		if s[i] == '1':
			st = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			end = i
			break
	ans = max(n, max((end + 1) * 2, (n - st) * 2))
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	x = -1
	for i in range(n):
		if s[i] == '1':
			x = i
			break
	if x == -1:
		print(n)
		continue
	else:
		for i in range(x):
			if s[n - 1 - i] == '1':
				x = min(x, i)
				break
		print(2 * n - 2 * x)


q = int(input())
for i in range(q):
	n = int(input())
	ans = 0
	a = [int(i) for i in list(input())]
	for i in range(n):
		if a[i] == 1:
			ans = max(max((i + 1) * 2, 2 * n - (i + 1) * 2 + 2), ans)
	print(max(n, ans))


t = int(input())

def solve():
	n = int(input())
	s = input()
	sc = 0
	for i in s:
		if i == '1':
			sc += 1
	if sc == 0:
		return '%s' % n
	counter = 0
	left = 0
	for i in range(n):
		if s[i] == '1':
			counter += 1
		if counter == sc:
			left = i + 1 + max(n - i, i + 1)
			break
	counter = 0
	right = 0
	s = s[::-1]
	for i in range(n):
		if s[i] == '1':
			counter += 1
		if counter == sc:
			right = i + 1 + max(n - i, i + 1)
			break
	return '%s' % max(left, right)
for i in range(t):
	print(solve())


t = int(input())
for i in range(t):
	l = int(input())
	x = list(input())
	(left, right) = (-1, -1)
	stairs = 0
	for j in range(l):
		if x[j] == '1':
			stairs += 1
			if left == -1:
				left = j
			right = j
	left = l - left
	right += 1
	if stairs == 0:
		left = 0
		right = 0
	d1 = l + stairs
	d2 = max(left, right) * 2
	print(max(d1, d2))


k = int(input())
for _ in range(k):
	n = int(input())
	s = input()
	l = None
	r = n
	for i in range(n):
		if s[i] == '1':
			r = i
			if l == None:
				l = i
	if l == None:
		print(n)
	else:
		print(2 * max(n - l, r + 1))


def reverse(s):
	st = ''
	for i in s:
		st = i + st
	return st
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	t1 = s.count('1')
	if t1 == 0:
		print(n)
	elif t1 == n:
		print(2 * n)
	else:
		c = 0
		for j in range(t1):
			t2 = s.find('1', c)
			c = t2 + 1
		kq1 = max(n + 1, 2 * c, n + t1)
		stp = reverse(s)
		kq2 = 0
		c = 0
		for j in range(t1):
			t2 = stp.find('1', c)
			c = t2 + 1
		kq2 = kq2 + max(n + 1, 2 * c, n + t1)
		kq = max(kq1, kq2)
		print(kq)


def solve(s, n):
	mx = n
	for i in range(n):
		if s[i] == '1':
			mx = max(mx, max(2 * (i + 1), (n - i) * 2))
	return mx
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	if s[0] == '1' or s[-1] == '1':
		print(2 * n)
	else:
		ans = solve(s, n)
		print(ans)


def solve():
	n = int(input())
	s = input()
	mn = mx = None
	for i in range(n):
		if s[i] == '0':
			continue
		if mn is None or mn > i:
			mn = i
		if mx is None or mx < i:
			mx = i
	ans = n
	if mn is not None:
		ans = max(ans, (n - mn) * 2)
	if mx is not None:
		ans = max(ans, (1 + mx) * 2)
	print(ans)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input()]
	if 1 in a:
		if a[0] == 1 or a[-1] == 1:
			print(2 * n)
		else:
			ans = n + 1
			x = -1
			for i in range(n):
				if a[i] == 1:
					x = i
					break
			y = 0
			for i in range(n):
				if a[i] == 1:
					y = i
			for i in range(n):
				if a[i] == 1:
					ans = max(ans, max(i + 1, n - i))
			print(max(ans, (x + 1) * 2, (n - x) * 2, (n - y) * 2, (y + 1) * 2))
	else:
		print(n)


import math
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	left = next((i for i in range(n) if s[i] == '1'), None)
	right = next((i for i in range(n - 1, -1, -1) if s[i] == '1'), None)
	if left is None:
		print(n)
	else:
		r1 = 1 + n
		r2 = 2 * (right + 1)
		r3 = 2 * (n - left)
		res = max(r1, r2, r3)
		print(res)


T = int(input())
for t in range(T):
	n = int(input())
	s = input()
	first1 = -1
	last1 = -1
	for i in range(n):
		if s[i] == '1':
			if first1 == -1:
				first1 = i
			last1 = i
	if first1 == -1:
		print(n)
		continue
	ans = 2 * max(last1 + 1, n - first1)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	a = s[0:n // 2]
	b = s[n // 2:n]
	b = b[::-1]
	if '1' in a:
		k1 = a.find('1')
	else:
		k1 = -1
	if '1' in b:
		k2 = b.find('1')
	else:
		k2 = -1
	if '1' not in s:
		print(n)
	else:
		if k1 == -1:
			k = k2
		elif k2 == -1:
			k = k1
		elif k1 > k2:
			k = k2
		elif k1 < k2:
			k = k1
		else:
			k = k1
		print(2 * n - 2 * k)


t = int(input())
for t in range(t):
	n = int(input())
	stairs = list(input())
	MAX = 0
	res = 0
	if n % 2 == 0:
		mid = n // 2 - 1
	else:
		mid = n // 2
	if stairs.count('1') == 0:
		print(n)
	elif stairs.count('1') == n:
		print(n * 2)
	else:
		for i in range(n):
			if stairs[i] == '1':
				imax = max((i + 1) * 2, (n - i) * 2)
				MAX = max(imax, MAX)
		print(MAX)


import sys, math
input = sys.stdin.readline
t = int(input())
for r in range(t):
	n = int(input())
	s = input().strip('\n')
	rooms = n
	for i in range(n):
		if s[i] == '1':
			a = max(n - i, i + 1)
			rooms = max(rooms, a * 2)
	print(rooms)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	s_rev = s[::-1]
	Left_Loc = -1
	Right_Loc = -1
	for i in range(n):
		if s[i] == '1':
			Left_Loc = i
			break
	for i in range(n):
		if s_rev[i] == '1':
			Right_Loc = i
			break
	if Left_Loc != -1:
		print(max(n, 2 * (n - Left_Loc), 2 * (n - Right_Loc)))
	else:
		print(n)


t = int(input())
for _ in range(t):
	n = int(input())
	s = '0' + str(input())
	if s.count('1') == 0:
		print(n)
	elif s.rfind('1') >= n - s.find('1') + 1:
		print(s.rfind('1') * 2)
	else:
		print((n - s.find('1') + 1) * 2)


t = int(input())
for _ in range(t):
	n = int(input())
	s = str(input())
	(mini, maxi) = (n, -1)
	for i in range(n):
		if s[i] == '1':
			mini = min(mini, i)
			maxi = max(maxi, i)
	if mini == n:
		print(n)
	else:
		print(max(n, 2 * max(maxi + 1, n - mini)))


for _ in range(int(input())):
	n = int(input())
	s = str(input())
	a = []
	for j in range(n):
		a.append(int(s[j]))
	if 1 not in set(a):
		print(n)
	else:
		b = a[::-1]
		start = n
		end = 0
		for i in range(n // 2 + 1):
			if a[i] == 1:
				start = i
				break
			else:
				continue
		for i in range(n - 1, n // 2 - 1, -1):
			if a[i] == 1:
				end = i
				break
			else:
				continue
		print(2 * max(n - start, end + 1))


def find_max(arr, n):
	maxm = n
	m = -1
	for i in range(n):
		if arr[i] == '1':
			m = max(m, i, n - 1 - i)
	return max(maxm, 2 * (m + 1))
t = int(input())
for i in range(t):
	n = int(input())
	arr = input()
	print(find_max(arr, n))


t = int(input())
for g in range(t):
	n = int(input())
	s = input()
	li = [int(i) for i in s]
	if max(li) == 0:
		print(n)
	elif min(li) == 1:
		print(2 * n)
	elif li.count(1) == 1:
		ind = li.index(1) + 1
		print(max(ind * 2, (n - ind + 1) * 2, n + 1))
	else:
		f = 0
		l = 0
		for i in range(n):
			if li[i] == 1:
				f = i + 1
				break
		for i in range(n - 1, f - 2, -1):
			if li[i] == 1:
				l = i + 1
				break
		print(max(n + 1, (l - f + 1) * 2 + f - 1, (l - f + 1) * 2 + n - l, n + 2, f * 2, (n - l + 1) * 2, (n - f + 1) * 2, l * 2))


from bisect import bisect
from collections import defaultdict
from math import gcd, sqrt, ceil
from collections import Counter
import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())
for _ in range(t):
	ans = 0
	n = int(input())
	s1 = input()
	posn1 = -1
	posn2 = -1
	s2 = s1[::-1]
	for i in range(n):
		if s1[i] == '1':
			posn1 = i
	for i in range(n):
		if s2[i] == '1':
			posn2 = i
	posn1 += 1
	posn2 += 1
	print(max(2 * posn1, 2 * posn2, n))


t = int(input())
for _ in range(t):
	n = int(input())
	s = str(input())
	one_inds = []
	for i in range(n):
		if s[i] == '1':
			one_inds.append(i)
	ans = n
	if len(one_inds) > 0:
		ans = max(ans, 2 * (one_inds[-1] + 1))
		ans = max(ans, 2 * (n - one_inds[0]))
	print(ans)


q = int(input())
for _ in range(q):
	a = int(input())
	b = input()
	cc = b.count('1')
	if cc == 0:
		print(a)
	else:
		l = b.index('1')
		r = b.rindex('1')
		if l == 0 or r == a - 1:
			print(2 * a)
		else:
			print(2 * (a - min(l, a - 1 - r)))


t = int(input())
for test in range(t):
	rooms = int(input())
	stairs = input()
	first_stair = stairs.find('1')
	if first_stair == -1:
		first_stair = None
	last_stair = rooms - 1 - stairs[::-1].find('1')
	if last_stair == -1:
		last_stair == None
	if first_stair != None:
		starting_at_left = (last_stair + 1) * 2
		starting_at_right = (rooms - first_stair) * 2
		print(max(starting_at_left, starting_at_right))
	else:
		print(rooms)


def ab():
	b = int(input())
	c = list(map(int, input()))
	if c.count(1) == 1:
		m = c.index(1)
		if m >= 0:
			n = (m + 1) * 2
		c.reverse()
		y = c.index(1)
		if y >= 0:
			r = (y + 1) * 2
		if m >= 0 and y >= 0:
			if n > r:
				print(n)
			else:
				print(r)
	if c.count(1) > 1:
		u = c.index(1)
		c.reverse()
		e = c.index(1)
		if u >= e:
			print((b - e) * 2)
		else:
			print((b - u) * 2)
	if c.count(1) == 0:
		print(b)
n = input()
for i in range(0, int(n)):
	ab()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	(x, y) = (s.find('1'), n - s.rfind('1') - 1)
	if x == -1:
		print(n)
	else:
		print((n - min(x, y)) * 2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(a, b) = (-1, -1)
	for i in range(n):
		if s[i] == '1':
			a = i
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			b = n - 1 - i
	if a == -1 and b == -1:
		print(n)
	else:
		print((max(a, b) + 1) * 2)


tc = int(input())
for _ in range(tc):
	n = int(input())
	rr = input().strip()
	rooms = 0
	(beg, end) = (-1, -1)
	for (idx, char) in enumerate(rr):
		if char == '1':
			rooms += 1
			if beg == -1 or beg > idx:
				beg = idx
			if end == -1 or end < idx:
				end = idx
	ans = 0
	if rooms == 0:
		ans = n
	elif rooms == 1:
		if beg == 0 or beg == n - 1:
			ans = 2 * n
		else:
			ans = 2 * max(beg + 1, n - beg)
	elif beg == 0 or end == n - 1:
		ans = 2 * n
	else:
		ans += 2 * max(n - beg, end + 1)
	print(ans)


import math
t = int(input())
for i in range(t):
	n = int(input())
	x = input()
	if '1' not in x:
		print(len(x))
	else:
		j_max = 0
		j_min = 9999999
		for j in range(len(x)):
			if x[j] == '1':
				j_min = min(j, j_min)
				j_max = max(j, j_max)
		print(max(j_max + 1, len(x) - j_min) * 2)


t = int(input())
for _ in range(t):
	n = int(input())
	rooms = str(input())
	left = rooms.find('1') + 1
	right = n - rooms.rfind('1')
	if left == 0:
		total = n
	elif left < right:
		total = (n - left + 1) * 2
	elif right != 0:
		total = (n - right + 1) * 2
	print(total)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	n = iinp()
	s = inp()
	if '1' in s:
		(i1, i2) = (s.index('1'), s[::-1].index('1'))
		print(2 * (n - min(i1, i2)))
	else:
		print(n)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		S = input()
		c = S.count('1')
		if c == 0:
			print(n)
		else:
			preidx = S.find('1')
			sufidx = S[::-1].find('1')
			idx = min(preidx, sufidx)
			print(max(n + c, 2 * n - 2 * idx))
main()


t = int(input())
for i in range(0, t):
	n = int(input())
	s = input()
	k = list(s)
	l = n // 2
	b = []
	if k.count('1') == 0:
		print(n)
	elif k.count('0') == 1 or (k.count('1') == 1 and k.index('1') == 0):
		print(n * 2)
	else:
		for j in range(0, l):
			if k[j] == '1':
				f = (n - j) * 2
				b.append(f)
		for j in range(l, n):
			if k[j] == '1':
				f = (j + 1) * 2
				b.append(f)
		print(max(b))


t = int(input())
for _ in range(t):
	n = int(input())
	c = input()
	i = 0
	while i < len(c) and c[i] == '0':
		i += 1
	f = i
	if f == len(c):
		print(len(c))
		continue
	i = len(c) - 1
	while i > 0 and c[i] == '0':
		i -= 1
	l = i
	a = l + 1
	b = len(c) - f
	if a > b:
		print(a * 2)
	else:
		print(b * 2)


for _ in [0] * int(input()):
	n = int(input())
	a = (*map(int, input()),)
	r = n
	if sum(a):
		(x, y) = (a.index(1), a[::-1].index(1))
		r = max(r, (n - x) * 2, (n - y) * 2)
	print(r)


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	if s[0] == '1' or s[n - 1] == '1':
		print(2 * n)
	else:
		fromstart = s.find('1')
		if fromstart == -1:
			print(n)
		else:
			print(2 * max(n - s.find('1'), 1 + s.rfind('1')))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import math

def solve(t):
	n = int(input().strip())
	stairs = input().strip()
	(k, l) = (float('inf'), float('inf'))
	i = 0
	while i < n:
		if stairs[i] == '1':
			k = i
			break
		i += 1
	i = 0
	while i < n:
		if stairs[n - 1 - i] == '1':
			l = i
			break
		i += 1
	kl = min(k, l)
	if kl == float('inf'):
		return n
	else:
		return 2 * (n - kl)

def main():
	tc = int(input().strip())
	for t in range(1, tc + 1):
		print(solve(t))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import collections
t = int(input())
for q in range(0, t):
	n = int(input())
	a = input()
	d = collections.Counter(a)
	if d['1'] == 0:
		print(n)
	elif d['0'] == 0:
		print(2 * n)
	elif a[0] == '1' or a[n - 1] == '1':
		print(2 * n)
	else:
		m1 = -1
		m2 = -1
		for i in range(0, n):
			if a[i] == '1':
				m1 = i
		for i in range(n - 1, -1, -1):
			if a[i] == '1':
				m2 = i
		m2 = n - 1 - m2
		m = max(m1, m2)
		print((m + 1) * 2)


t = int(input())

def roomCount(n, s):
	count = 0
	if s[0] == '1' or s[-1] == '1':
		print(2 * n)
		return
	last = -1
	first = -1
	for i in range(len(s)):
		if s[i] == '1':
			if first == -1:
				first = i
			last = i
			count += 1
	if first != -1:
		print(max(count + n, 2 * (n - first), 2 * (last + 1)))
	else:
		print(n)
	return
for _ in range(t):
	n = int(input())
	s = input()
	roomCount(n, s)


q = int(input())
while q > 0:
	n = int(input())
	a = input()
	first = n
	last = 0
	for i in range(0, n):
		if a[i] == '1':
			first = i
			break
	for (i, e) in reversed(list(enumerate(a))):
		if a[i] == '1':
			last = i + 1
			break
	rooms = max(n - first, last)
	ans = max(rooms * 2, n)
	print(ans)
	q -= 1


for _ in range(int(input())):
	(n, s) = (int(input()), input())
	if '1' not in s:
		print(n)
	else:
		print((max(''.join(reversed(s)).rindex('1'), s.rindex('1')) + 1) * 2)


q = int(input())
for _ in range(q):
	n = int(input())
	s = input()
	if '1' not in s:
		print(n)
	else:
		print(2 * max(n - s.find('1'), s.rfind('1') + 1))


def fun():
	n = int(input())
	s = input()
	l = n
	r = 0
	if s[0] == '1' or s[n - 1] == '1':
		print(2 * n)
		return
	for i in range(n):
		if s[i] == '1':
			l = min(l, i + 1)
			r = i + 1
	if r == 0:
		print(n)
		return
	print(max(2 * l, 2 * (n - l + 1), 2 * r, 2 * (n - r + 1)))
t = int(input())
for ii in range(t):
	fun()


n = int(input())
for i in range(n):
	test = 0
	k = int(input())
	ch = input()
	st = [int(l) for l in ch]
	st_2 = st.copy()
	st_2.reverse()
	for q in range(len(st)):
		if st[q] == 1:
			test = 1
			print(max(len(st), (len(st) - q) * 2))
			break
		if st_2[q] == 1:
			test = 1
			print(max(len(st), (len(st) - q) * 2))
			break
	if test == 0:
		print(len(st))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(input())
	if l[-1] == '1' or l[0] == '1':
		print(n * 2)
	elif '1' not in l:
		print(n)
	else:
		b = l.index('1')
		c = l[::-1].index('1')
		print((n - min(b, c)) * 2)


t = int(input())
for test in range(t):
	n = int(input())
	s = input()
	res = n
	for i in range(n):
		if s[i] == '1':
			res = max(res, max((i + 1) * 2, (n - i) * 2))
	print(res)


def calculate(s):
	ans = n
	for i in range(n):
		if s[i] == '1':
			ans = max(ans, max(2 * (i + 1), (n - i) * 2))
	return ans
t = int(input())
while t > 0:
	n = int(input())
	s = input()
	if s[0] == '1' or s[n - 1] == '1':
		print(2 * n)
	else:
		ans = calculate(s)
		print(ans)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input()))
	if l[0] == 1 or l[-1] == 1:
		print(2 * n)
	else:
		ans = n
		a = 0
		b = 0
		for t in range(n):
			if l[t] == 1:
				a = (t + 1) * 2
				b = (n - t) * 2
				z = max(a, b)
				ans = max(ans, z)
		print(ans)


import sys
q = int(sys.stdin.readline().rstrip())
while q:
	q -= 1
	n = int(sys.stdin.readline().rstrip())
	room = sys.stdin.readline().rstrip()
	lm = -1
	rm = -1
	for (ind, r) in enumerate(room):
		if r == '1':
			lm = ind
			break
	for (ind, r) in enumerate(reversed(room), 1):
		if r == '1':
			rm = len(room) - ind
			break
	if lm == -1 and rm == -1:
		print(n)
	elif lm == rm:
		print(2 * max(lm + 1, n - lm))
	else:
		print(2 * max(rm + 1, n - lm))


for i in range(int(input())):
	a = int(input())
	s = input()
	ans1 = 0
	ans2 = 0
	if '1' not in s:
		print(len(s))
	elif '0' not in s:
		print(2 * len(s))
	elif '1' in s and '0' in s:
		q = s.rfind('1')
		for num in s[:q + 1]:
			if num == '0':
				ans1 = ans1 + 1
			else:
				ans1 = ans1 + 2
		ans1 = ans1 + len(s[q + 1:])
		t = ans1
		m = s[::-1]
		h = m.rfind('1')
		for num in m[:h + 1]:
			if num == '0':
				ans2 = ans2 + 1
			else:
				ans2 = ans2 + 2
		ans2 = ans2 + len(m[h + 1:])
		ans3 = 2 * (q + 1)
		ans4 = 2 * (h + 1)
		print(max(ans1, ans2, ans3, ans4))


R = lambda : int(input())
for i in range(R()):
	b = R()
	s = input()
	n = s.find('1')
	if n == -1:
		print(b)
	else:
		print(2 * max(b - n, s.rfind('1') + 1))


inp = lambda cast=int: [cast(x) for x in input().split()]
printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs)
(t,) = inp()
for _ in range(t):
	(n,) = inp()
	(s,) = inp(str)
	print(2 * n - min(s.index('1'), s[::-1].index('1')) * 2 if '1' in s else n)


t = int(input())
for i in range(t):
	n = int(input())
	room = input()
	ans = 0
	ansOPPO = room[::-1]
	for j in range(n):
		if room[j] == '1' or ansOPPO[j] == '1':
			ans = n - j
			break
	if ans > 0:
		print(ans * 2)
	else:
		print(n)


def main():
	n = int(input())
	bins = input()
	(lmost, rmost) = (-1, -1)
	for i in range(n):
		if bins[i] == '1':
			rmost = i
			if lmost == -1:
				lmost = i
	if lmost == -1:
		print(n)
	else:
		print(max(2 * (rmost + 1), 2 * (n - lmost)))
kase = int(input())
for _ in range(kase):
	main()


n = int(input())
for i in range(n):
	p = int(input())
	s = input()
	h2 = s.rfind('1')
	h1 = s.find('1')
	if h2 == -1:
		print(p)
	elif h2 + 1 > p - h1:
		print((h2 + 1) * 2)
	else:
		print((p - h1) * 2)


t = int(input())
for i in range(t):
	r = int(input())
	m = str(input())
	m1 = 0
	m2 = 0
	for j in range(len(m)):
		if m1 == m2 and m[j] == '1':
			m1 = j
		if m[j] == '1':
			m2 = j + 1
	if m2 == 0:
		print(r)
	else:
		print(max(2 * (r - m1), 2 * m2))


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	k = [i for i in range(n) if s[i] == '1']
	ans = n
	for i in k:
		ans = max(ans, 2 * max(i + 1, n - i))
	print(ans)


a = int(input())
for i in range(a):
	b = int(input())
	c = input()
	cnt = 0
	maxi = 0
	if c[0] == '1' or c[-1] == '1':
		print(b * 2)
	elif c.count('0') == b:
		print(b)
	elif b % 2 == 0:
		x = round(b / 2)
		for k in range(0, b):
			if c[k] == '1' and k + 1 <= x:
				y = b - k
				cnt = y * 2
				if cnt > maxi:
					maxi = cnt
			elif c[k] == '1' and k + 1 > x:
				cnt = (k + 1) * 2
				if cnt > maxi:
					maxi = cnt
		print(maxi)
	else:
		y = round(b // 2)
		for j in range(0, b):
			if c[j] == '1' and j + 1 <= y:
				cnt = (b - j) * 2
				if cnt > maxi:
					maxi = cnt
			elif c[j] == '1' and j + 1 > y:
				cnt = (j + 1) * 2
				if cnt > maxi:
					maxi = cnt
		print(maxi)


for T in range(int(input())):
	n = int(input())
	s = input()
	l = 0
	r = 0
	for i in range(len(s)):
		if s[i] == '1':
			l = len(s) - i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			r = i + 1
			break
	b = max(l, r)
	if b == 0:
		print(n)
	else:
		print(b * 2)


import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	if s.count('1') == 0:
		print(n)
		continue
	ans = 0
	Ans = [0]
	for i in range(n):
		if s[i] == '1':
			Ans.append(i + 1)
	a = Ans[-1]
	ans = a * 2
	Ans = []
	s = s[::-1]
	for i in range(n):
		if s[i] == '1':
			Ans.append(i + 1)
	a = Ans[-1]
	ans = max(ans, a * 2)
	print(ans)


T = int(input())
for _ in range(T):
	n = int(input())
	s = list(map(int, input()))
	rev = s[::-1]
	if s.count(1) >= 1:
		index_s = s.index(1)
		index_reverse = rev.index(1)
		indexmaxrev = len(s) - index_reverse - 1
		indexmaxs = len(s) - index_s - 1
		index = max(indexmaxrev, indexmaxs)
		zimmer_rechts = len(s) - (index + 1) + 1
		zimmer_links = index + 1
		links = index + 1 + zimmer_links
		rechts = index + 1 + zimmer_rechts
		if rechts > links:
			print(rechts)
		else:
			print(links)
	else:
		print(len(s))


for i in range(int(input())):
	length = int(input())
	rooms = input()
	if rooms.count('0') == 0:
		print(2 * length)
	elif rooms.count('1') == 0:
		print(length)
	elif rooms[0] == '1' or rooms[-1] == '1':
		print(2 * length)
	else:
		room_index = rooms.index('1')
		room_index1 = rooms[::-1].index('1')
		if room_index >= room_index1:
			print(2 * (length - room_index1))
		else:
			print(2 * (length - room_index))


t = int(input())
while t:
	n = int(input())
	a = input()
	if a.count('1') == 0:
		print(n)
	else:
		for i in range(n):
			if a[i] == '1':
				break
		for j in range(n):
			if a[n - 1 - j] == '1':
				break
		print(max(n + 1, 2 * (i + 1), 2 * (j + 1), 2 * (n - i), 2 * (n - j)))
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = 0
	ok = False
	for i in range(n):
		if s[i] == '1':
			ok = True
			break
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			ok = True
			break
	if ok:
		print(max(max(j + 1, n - j) * 2, max(i + 1, n - i) * 2))
	else:
		print(n)


for _ in range(int(input())):
	n = int(input())
	s = input()
	t = s[::-1]
	try:
		temps = s.index('1') + 1
		tempt = t.index('1') + 1
		temps = n - temps + 1
		tempt = n - tempt + 1
		res = max(temps, tempt)
		res = res * 2
	except ValueError:
		res = n
	print(res)


def solve(a):
	left0 = 0
	right0 = 0
	if '1' not in a:
		return len(a)
	for i in a:
		if i == '0':
			left0 += 1
		else:
			break
	for i in a[::-1]:
		if i == '0':
			right0 += 1
		else:
			break
	return len(a) * 2 - min(left0, right0) * 2

def main():
	t = int(input())
	for _ in range(t):
		_ = int(input())
		a = input()
		print(solve(a))
main()


t = int(input())
for _ in range(t):
	n = int(input())
	s = str(input())
	ans = 0
	for i in range(0, n):
		if int(s[i]) == 1:
			temp = 0
			if i + 1 <= n / 2:
				temp = (n - i) * 2
			else:
				temp = (i + 1) * 2
			if temp > ans:
				ans = temp
	if ans == 0:
		ans = n
	print(ans)


T = eval(input())
for i in range(T):
	n = eval(input())
	stair = input()
	left = 0
	right = n - 1
	while left < n and stair[left] != '1':
		left += 1
	while right >= 0 and stair[right] != '1':
		right -= 1
	if left == n:
		print(n)
	else:
		ans = max(right + 1, n - left) * 2
		print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(input())
	(x, y) = (-1, -1)
	for i in range(n):
		if l[i] == '1' and x == -1:
			x = i
		if l[i] == '1':
			y = i
	if x == -1:
		print(n)
	else:
		z = max(n - x, y + 1)
		print(2 * z)


t = int(input())
for i in range(t):
	m = int(input())
	n = int(input())
	a = 0
	d = 0
	max = 0
	while n >= 1:
		a = a + 1
		if n % 10 != 0:
			d = d + 1
			if a <= m // 2:
				if 2 * (m - a + 1) > max:
					max = 2 * (m - a + 1)
			elif 2 * a > max:
				max = 2 * a
		n = n // 10
	if d > 1:
		if m + d > max:
			max = m + d
	if a != 0:
		print(max)
	else:
		print(m)


t = int(input())
f = 0
l1 = 0
l2 = 0
for _ in range(t):
	n = int(input())
	s = input()
	if s[0] == '1' and s[len(s) - 1] == '1':
		print(2 * n)
	else:
		for i in range(len(s)):
			if s[i] == '1':
				l2 = i
				if f == 0:
					l1 = i
				f = 1
		if f == 1:
			l2 = len(s) - 1 - l2
			print(2 * (n - min(l2, l1)))
		else:
			print(n)
	f = 0
	l1 = 0
	l2 = 0


import math

def input_int():
	return list(map(int, input().split()))

def solve():
	[n] = input_int()
	string = input()
	for i in range(0, math.ceil(n / 2)):
		if string[i] == '1' or string[n - 1 - i] == '1':
			print((n - i) * 2)
			return
	print(n)
[q] = input_int()
for q1 in range(0, q):
	solve()


import math
t = int(input())
for _ in range(t):
	n = int(input())
	str = input()
	cur_sum = 0
	m_sum = 0
	for i in range(len(str)):
		x = int(str[i])
		cur_sum += 1
		if x == 1:
			m_sum = max(m_sum, cur_sum * 2)
		x = int(str[n - i - 1])
		if x == 1:
			m_sum = max(m_sum, cur_sum * 2)
		m_sum = max(m_sum, cur_sum)
	print(m_sum)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	left = n + 1
	right = -1
	for i in range(n):
		if a[i] == '1':
			if left == n + 1:
				left = i
			right = i
	if right == -1:
		print(n)
	else:
		fl = right + 1 + max(right + 1, n - right)
		left = n - left - 1
		fr = left + 1 + max(left + 1, n - left)
		print(max(fl, fr))


t = int(input())
for _ in range(t):
	n = int(input())
	stairs = [True if x == '1' else False for x in input()]
	res = 0
	first_stairs_index = -1
	last_stairs_index = -1
	for (index, with_stairs) in enumerate(stairs):
		res += 1
		if with_stairs:
			res += 1
			last_stairs_index = index
			if first_stairs_index == -1:
				first_stairs_index = index
	r = [0 if first_stairs_index == -1 else 2 * (first_stairs_index + 1), 0 if first_stairs_index == -1 else 2 * (n - first_stairs_index), 0 if last_stairs_index == -1 else 2 * (last_stairs_index + 1), 0 if last_stairs_index == -1 else 2 * (n - first_stairs_index), res]
	print(max(r))


for _ in range(int(input())):
	n = int(input())
	s = input()
	mi = 1000000
	if set(s) == {'0'}:
		print(n)
		continue
	for i in range(n):
		if s[i] == '1':
			mi = i
			break
	s = s[::-1]
	for i in range(n):
		if s[i] == '1':
			mi = min(mi, i)
			break
	print(2 * (n - mi))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	s = list(s)
	if s[0] == '1' or s[n - 1] == '1':
		print(2 * n)
	else:
		one = 0
		ans = 0
		l = 10000
		r = 10000
		for i in range(n):
			if s[i] == '1':
				l = i
				break
		for i in range(n):
			if s[n - 1 - i] == '1':
				r = i
				break
		if l == 10000 and r == 10000:
			print(n)
		else:
			ans = min(l, r)
			x = 2 * (n - ans)
			y = 2 * (ans + 1)
			z = n
			print(max(x, max(y, z)))


from math import ceil
t = int(input())
while t > 0:
	n = int(input())
	a = input()
	(find, rind) = (-1, -1)
	for i in range(n):
		if a[i] == '1':
			find = i
			break
	find = n - find if find != -1 else -1
	for i in range(n - 1, -1, -1):
		if a[i] == '1':
			rind = i
			break
	print(max(n, 2 * find, 2 * (rind + 1)))
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	a = list(s)
	p1 = p2 = n // 2
	f1 = True
	one = a.count('1')
	if a[0] == '1' or a[n - 1] == '1':
		print(n * 2)
	elif one == 0:
		print(n)
	elif one == 1:
		p1 = a.index('1')
		print(max(p1 - 0, n - 1 - p1) * 2 + 2)
	else:
		for i in range(n):
			if a[i] == '1' and f1 == True:
				p1 = i
				f1 = False
			if a[i] == '1':
				p2 = i
		mn = min(p1 - 0, n - 1 - p2)
		print(2 * n - 2 * mn)


n = int(input())
f1 = []
for i in range(n):
	f = int(input())
	s = input()
	d = 0
	c = 0
	for j in range(f):
		if s[j] == '1':
			c = f + f - j - j
			break
		elif s[f - j - 1] == '1':
			c = f + f - j - j
			break
	if c == 0:
		c += f
	f1.append(c)
for i in range(n):
	print(f1[i])


t = int(input())
for i in range(t):
	n = int(input())
	string = input()
	total = 0
	for c in string:
		if c == '0':
			total += 1
		elif c == '1':
			total += 2
	l = len(string.lstrip('0'))
	r = len(string.rstrip('0'))
	total = max(total, 2 * l, 2 * r)
	print(total)


I = input
for c in '0' * int(I()):
	I()
	s = I()
	print(len(2 * max(s, s[::-1]).lstrip(c) or s))


import sys
t = int(input().strip())
for a0 in range(t):
	n = int(input())
	s = input()
	if s.count('1') == 0:
		print(n)
	elif s.count('1') == 1:
		a = 1
		for i in s:
			if i == '1':
				break
			else:
				a += 1
		print(max(2 * a, 2 * (n - a + 1)))
	elif s[0] == '1' or s[len(s) - 1] == '1':
		print(2 * n)
	else:
		m = s[::-1]
		a = 0
		for i in s:
			if i == '1':
				break
			else:
				a += 1
		b = n - 1
		for i in m:
			if i == '1':
				break
			else:
				b -= 1
		x = s[0:a + 1]
		y = s[b:]
		t = max(x.count('0'), y.count('0'))
		print(2 * (b - a + 1) + 2 * t)


t = int(input())
for i in range(t):
	n = int(input())
	flag = 0
	s = input()
	l = list(s)
	i = 0
	for i in range(n // 2 + 1):
		if l[i] == '1' or l[n - 1 - i] == '1':
			flag = 1
			if i <= (n - 1) // 2:
				print(2 * (n - i))
				break
			else:
				print(2 * (i + 1))
				break
	if flag == 0:
		print(n)


for _ in range(int(input())):
	n = int(input())
	u = list(map(int, list(input())))
	if u[:] == [0] * n:
		print(n)
		continue
	a = -1
	b = -1
	for i in range(n):
		if u[i] == 1:
			a = i
			break
	for i in range(n - 1, -1, -1):
		if u[i] == 1:
			b = i
			break
	print(max((n - a) * 2, (b + 1) * 2, n))


def max_min(string):
	res = [-1] * 2
	for i in range(0, len(string)):
		if string[i] == '1':
			res[0] = i
			break
	for i in range(len(string) - 1, 0, -1):
		if string[i] == '1':
			res[1] = i
			break
	return res
t = int(input())
for i in range(t):
	rooms = int(input())
	st = input()
	indx = max_min(st)
	if indx[0] == -1 and indx[1] == -1:
		print(rooms)
	else:
		print(max((rooms - indx[0]) * 2, (indx[1] + 1) * 2))


t = int(input())
for i in range(0, t):
	n = int(input())
	s = input()
	start = str.find(s, '1')
	fin = str.find(s[::-1], '1')
	if start == -1:
		print(n)
	else:
		ans = n * 2 - min(start, fin) * 2
		print(ans)


def index_all(staircase, l_i):
	a = staircase.index('1')
	count_1 = staircase.count('1')
	for i in range(count_1):
		b = staircase.index('1', a, len(staircase))
		l_i.append(b + 1)
		a = b + 1
q = int(input())
ans = []
for i in range(q):
	index1 = 0
	l_i = []
	n = int(input())
	staircase = input()
	if staircase.__contains__('1') == False:
		ans.append(n)
	elif staircase[0] == '1' or staircase[-1] == '1':
		ans.append(n * 2)
	else:
		index_all(staircase, l_i)
		max_l_i = max(l_i)
		min_l_i = min(l_i)
		if max_l_i >= abs(n - min_l_i + 1):
			ans.append(max_l_i * 2)
		else:
			ans.append(abs(n - min_l_i + 1) * 2)
for e in ans:
	print(e)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ones = s.count('1')
	if ones == 0:
		print(n)
	elif s[0] == '1' or s[-1] == '1':
		print(2 * n)
	else:
		(spos, endpos) = (0, 0)
		for (i, j) in enumerate(s):
			if j == '1':
				spos = i
				break
		for (i, j) in enumerate(s[-1::-1]):
			if j == '1':
				endpos = i
				break
		endpos = n - endpos - 1
		spos = n - spos
		if spos < endpos + 1:
			print(2 * (endpos + 1))
		else:
			print(2 * spos)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if s[0] == '1' or s[-1] == '1':
		print(2 * n)
	else:
		ans = n
		for i in range(n):
			if s[i] == '1':
				ans = max(ans, 2 * (n - i))
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				ans = max(ans, 2 * (i + 1))
				break
		print(ans)


t = int(input())
for i in range(0, t):
	n = int(input())
	rooms = input()
	left = rooms.find('1')
	rigth = rooms.rfind('1')
	if left > -1 or rigth > -1:
		qtd = 2 * max(n - left, rigth + 1)
	else:
		qtd = n
	print(qtd)


T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	if s[0] == 1 or s[n - 1] == 1:
		print(2 * n)
		continue
	if s.find('1') == -1:
		print(n)
		continue
	if s.find('0') == -1:
		print(2 * n)
		continue
	x = s.index('1')
	y = s.rindex('1')
	a = (n - x) * 2
	b = (y + 1) * 2
	if b < a:
		print(a)
	else:
		print(b)


for i in range(int(input())):
	x = int(input())
	y = input()
	m = 0
	for i in range(x):
		if y[i] == '1':
			m = max(m, i + 1)
	for i in range(1, x + 1):
		if y[-i] == '1':
			m = max(m, i)
	print(m * 2) if m != 0 else print(x)


import sys
import os
from io import IOBase, BytesIO

def main():
	for tc in range(int(input())):
		n = int(input())
		s = input()
		ans = 0
		(j, k) = (0, 0)
		for i in range(n):
			if s[i] == '1':
				break
			else:
				j += 1
		if j == n:
			print(n)
			continue
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				break
			else:
				k += 1
		print(2 * n - 2 * min(j, k))
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		py2 = round(0.5)
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2 == 1:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().strip()
main()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	if int(s) > int(s[::-1]):
		s = s[::-1]
	count = 0
	last_one = -1
	count_one = 0
	chance = n
	for (i, j) in enumerate(s):
		if j == '1':
			last_one = i + 1
			chance += 1
	print(max([last_one * 2, n, chance]))


t = int(input())
for i in range(t):
	l = int(input())
	c = str(input())
	idx = -1
	flag = 0
	while flag == 0:
		idx += 1
		if idx == l:
			print(l)
			break
		if c[idx] == '1' or c[l - idx - 1] == '1':
			flag = 1
	else:
		print(2 * (l - idx))


t = int(input())
z = 0
while z < t:
	n = input()
	n = input()
	ans = len(n) * 2
	i = 0
	j = len(n) - 1
	while i <= j:
		if n[i] != '1' and i == j:
			ans -= 1
		elif n[i] != '1' and n[j] != '1':
			ans -= 2
		else:
			break
		i += 1
		j -= 1
	print(ans)
	z += 1


for q in range(int(input())):
	n = int(input())
	bi = input()
	l = bi.find('1')
	if l == -1:
		print(n)
		continue
	r = n - 1 - bi.rfind('1')
	print(2 * n - 2 * min(l, r))


t = int(input())
for i in range(0, t):
	n = int(input())
	stairs = input()
	if stairs.find('1') == -1:
		print(n)
	elif stairs[0] == '1' or stairs[len(stairs) - 1] == '1':
		print(n * 2)
	else:
		p1 = stairs.find('1')
		rs = stairs[::-1]
		p2 = rs.find('1')
		pos = min(p1, p2)
		nn = n - pos
		print(nn * 2)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(input())
	if '1' not in set(l):
		print(n)
	else:
		ind = l.index('1')
		li = l[::-1]
		ind = min(ind, li.index('1'))
		print(n * 2 - 2 * ind)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(input())
	b = list(reversed(a))
	if '1' in a:
		z = max(n - a.index('1'), n - b.index('1'))
		print(z * 2)
	else:
		print(n)


t = int(input())
for _ in range(t):
	n = int(input())
	s = [int(i) for i in input()]
	if 1 not in s:
		print(n)
	else:
		ind1 = 0
		ind2 = 0
		for i in range(n):
			if s[i] == 1:
				ind1 = i
				break
		for i in range(n):
			if s[i] == 1:
				ind2 = i
		ind1 = max(ind1 + 1, n - ind1)
		ind2 = max(ind2 + 1, n - ind2)
		print(2 * max(ind1, ind2))


for _ in range(int(input())):
	n = int(input())
	l = str(input())
	rf = l.rfind('1')
	lf = l.find('1')
	if rf == -1 or lf == -1:
		print(n)
	elif n - lf - 1 > rf:
		print((n - lf - 1 + 1) * 2)
	else:
		print((rf + 1) * 2)


import sys
(t,) = map(int, sys.stdin.readline().split())
for _ in range(t):
	(n,) = map(int, sys.stdin.readline().split())
	s = sys.stdin.readline().rstrip()
	res = n
	for i in range(n):
		if s[i] == '1':
			value = 2 * max(i + 1, n - i)
			res = max(res, value)
	print(res)


from math import ceil
R = lambda : list(map(int, input().split()))
n = int(input())
for _ in range(n):
	m = int(input())
	mass = list(map(int, input()))
	i = 0
	index = 0
	while mass[m - i - 1] == 0 and i < m:
		if mass[i] != 0:
			index = i
			break
		i += 1
		index = -i
	if index < 0:
		if m + index == 0:
			print(m)
		else:
			print((m + index) * 2)
	else:
		print((m - index) * 2)


t = int(input())
a = []
for i in range(t):
	maxx = 0
	n = int(input())
	minn = n + 1
	qwe = input()
	for q in range(1, n + 1):
		if qwe[q - 1] == '1':
			if q > maxx:
				maxx = q
			if q < minn:
				minn = q
	if maxx == 0:
		a.append(n)
	elif n - maxx < minn:
		a.append(n * 2 - (n - maxx) * 2)
	else:
		a.append(n * 2 - (minn - 1) * 2)
for w in a:
	print(w)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if s.find('1') != -1:
		ans = max(s.rfind('1') + 1 + max(s.rfind('1') + 1, n - s.rfind('1')), n - s.find('1') + max(s.find('1') + 1, n - s.find('1')))
	else:
		ans = n
	print(ans)


q = int(input())
for i in range(q):
	input()
	w = input()
	e = w.find('1')
	r = w.rfind('1')
	if r != -1:
		print(max((r + 1) * 2, (len(w) - e) * 2, len(w)))
	else:
		print(len(w))


for i in range(int(input())):
	n = int(input())
	s = input()
	if s.count('0') == n:
		print(n)
		continue
	elif s.count('1') == n:
		print(2 * n)
		continue
	elif s[:1] == '1' or s[n - 1:] == '1':
		print(2 * n)
	else:
		q = 0
		for i in range(n):
			if s[i] == '1':
				x = i + 1
				y = n - x
				res = max(x + y, 2 * x, 2 * (y + 1))
				q = max(res, q)
		print(q)


def program():
	n = int(input())
	s = list(input())
	for i in range(n):
		if s[i] == '1' or s[n - 1 - i] == '1':
			print(2 * (n - i))
			return 0
	print(n)
t = int(input())
for i in range(t):
	program()


test = int(input())
while test > 0:
	test -= 1
	x = int(input())
	st = input()
	count = 0
	if st == '1':
		print(2)
	elif st == '0':
		print(1)
	elif st[0] == '1' or st[-1] == '1':
		print(2 * x)
	elif '1' not in st:
		print(x)
	else:
		for i in range(x):
			if st[i] == '1':
				pos = i
		for i in range(x):
			if st[i] == '1':
				fs = i
				break
		(t1, t2) = (0, 0)
		if pos < x // 2:
			pos = x - pos
			t1 = pos * 2
		else:
			t1 = (pos + 1) * 2
		if fs < x // 2:
			fs = x - fs
			t2 = fs * 2
		else:
			t2 = (fs + 1) * 2
		print(max(t1, t2))


t = int(input())
for i in range(t):
	n = int(input())
	s = list(input())
	sr = list(reversed(s))
	if s.count('1') == 0:
		print(n)
	else:
		print((n - min(s.index('1'), sr.index('1'))) * 2)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(input())
	if a.count('1') == n:
		print(2 * n)
	elif a.count('0') == n:
		print(n)
	else:
		ans = n
		for i in range(0, len(a)):
			if a[i] == '1':
				ans = max(ans, (i + 1) * 2, (n - i) * 2)
		print(ans)


for _ in [0] * int(input()):
	n = int(input())
	s = input()
	m = max(len(s.lstrip('0')), len(s.rstrip('0')))
	print((n, 2 * m)[m > 0])


for _ in range(int(input())):
	n = int(input())
	a = list(input())
	ans = n
	for i in range(n):
		if a[i] == '1':
			ans = max(ans, 2 * (n - i), 2 * (i + 1))
	print(ans)


t = int(input())
for i in range(t):
	g = int(input())
	lis = list(map(int, input()))
	x = len(lis)
	countone = 0
	beforezero = 0
	m = 0
	for k in range(len(lis)):
		if lis[k] == 1:
			m = k
			countone = countone + 1
	if countone == 0:
		print(x)
		continue
	for j in range(len(lis)):
		if lis[j] == 1:
			break
	ans = max(2 * (m + 1), 2 * (x - j))
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	mi = 0
	ma = 0
	for (i, c) in enumerate(s):
		if c == '1':
			ma = i + 1
	for (i, c) in enumerate(s):
		if c == '1':
			mi = n - i
			break
	print(max(n, ma * 2, mi * 2))


import math
for _ in range(int(input())):
	n = int(input())
	rooms = str(input())
	ans = 0
	dp = [0] * n
	flag1 = 0
	flag2 = 0
	for i in range(n // 2):
		if rooms[i] == '1':
			dp[i] = n - i
			flag1 = 1
	for i in range(n // 2, n, 1):
		if rooms[i] == '1':
			dp[i] = i + 1
			flag2 = 1
	if flag1 == 0 and flag2 == 0:
		print(n)
	else:
		print(2 * max(dp))


from sys import stdin
input = stdin.readline
for i in range(int(input())):
	n = int(input())
	s = input().strip()
	x = s.find('1')
	y = s[::-1].find('1')
	if y == -1:
		print(n)
		continue
	a = max(x, n - x)
	b = max(y, n - y)
	print(max(a * 2, b * 2))


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	f = -1
	ind1 = -1
	ind2 = -1
	for i in range(0, n):
		if s[i] == '1':
			f = 1
			ind2 = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			f = 1
			ind1 = i
			break
	if f == -1:
		print(n)
	else:
		ans1 = max(ind1, n - ind1 - 1)
		ans1 += 1
		ans1 *= 2
		ans2 = max(ind2, n - ind2 - 1)
		ans2 += 1
		ans2 *= 2
		print(max(ans1, ans2))
	t -= 1


for _ in range(int(input())):
	n = int(input())
	st = input().strip()
	c1 = st.count('1')
	if st[0] == '1' or st[n - 1] == '1':
		print(2 * n)
	else:
		mx = n + c1
		for i in range(n):
			if st[i] == '1':
				mx = max(mx, 2 * (i + 1))
				mx = max(mx, 2 * (n - i))
		print(mx)


Q = int(input())
for q in range(Q):
	n = int(input())
	ladders = [int(i) for i in input()]
	nums = []
	for (num, i) in enumerate(ladders):
		if i == 1:
			nums.append(num)
	if len(nums) == 0:
		print(n)
	else:
		print(max(n - nums[0], nums[-1] + 1) * 2)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	c = n
	for i in range(n):
		if s[i] == '1':
			c = max(c, 2 * (i + 1), 2 * (n - i))
	print(c)


case = int(input())
for _ in range(case):
	size = int(input())
	inp = input()
	if inp[0] == '1' or inp[-1] == '1':
		print(size * 2)
	else:
		for left in range(size):
			if inp[left] == '1':
				break
		for right in range(size):
			if inp[size - 1 - right] == '1':
				break
		if left == right == size - 1:
			print(size)
		else:
			index = min(left, right)
			print((size - index) * 2)


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	first = -1
	last = -1
	for i in range(n):
		if s[i] == '1':
			first = i
			break
	if first != -1:
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				last = i
				break
	if first == -1:
		print(n)
	else:
		print(2 * max(n - first, last + 1))


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
t = int(input())
for i in range(0, t):
	n = int(input())
	a = input()
	if '1' not in a:
		print(n)
	else:
		k = a.index('1')
		k = n - k
		a = a[::-1]
		m = a.index('1')
		m = n - m
		print(max(n, 2 * k, 2 * m))


from math import ceil
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
n = ii()
for i in range(n):
	x = ii()
	y = input()
	x1 = -1
	x2 = -1
	if '1' in y:
		x1 = x - y.index('1')
		x2 = x - y[::-1].index('1')
	if x1 == -1 and x2 == -1:
		print(x)
	else:
		print(2 * max(x1, x2))


a = int(input())
for i in range(a):
	b = int(input())
	c = input()
	l = c.find('1')
	r = c.rfind('1')
	if l == -1:
		print(b)
	else:
		k1 = r + 1
		k2 = b - l
		print(max(k1, k2) * 2)


for i in range(int(input())):
	n = int(input())
	string = input()
	if '1' in string:
		last_index = n - 1 - string[::-1].index('1')
		first_index = string.index('1')
		m = max(2 * (last_index + 1), 2 * (n - first_index))
		count = 0
		for i in range(n):
			count += 1
			if string[i] == 1:
				count += 1
		print(max(m, count))
	else:
		print(n)


for i in range(int(input())):
	(n, s) = (int(input()), list(input()))
	if '1' not in s:
		print(n)
	else:
		(a, b) = (s.index('1'), s[::-1].index('1'))
		print(max(n - b, n - a) * 2)


for i in range(int(input())):
	n = int(input())
	s = input()
	try:
		i1 = n - s.index('1')
		i2 = s.rindex('1') + 1
		print(max(i1 * 2, i2 * 2))
	except:
		print(n)


for _ in range(int(input())):
	n = int(input())
	escadas = [i + 1 for (i, v) in enumerate(input()) if v == '1']
	res = 0
	if escadas:
		res = max(escadas[-1] * 2, (n - escadas[0] + 1) * 2)
	print(max(res, n))


n = int(input())
for i in range(n):
	a = int(input())
	bar = input()
	if bar.find('1') == -1:
		print(len(bar))
	else:
		print((max(len(bar) - 1 - bar.find('1'), len(bar) - 1 - bar[::-1].find('1')) + 1) * 2)


from sys import stdin
t = int(stdin.readline().rstrip())
while t > 0:
	n = int(stdin.readline().rstrip())
	s = stdin.readline().rstrip()
	(m1, m2, f) = (0, 0, 0)
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			f = 1
			m2 = (i + 1) * 2
			break
	for i in range(n):
		if s[i] == '1':
			f = 1
			m1 = (n - i) * 2
			break
	if f == 0:
		print(n)
	else:
		print(max(m1, m2))
	t -= 1


x = 0
y = 0
for i in range(int(input())):
	n = int(input())
	b = list(map(int, input()))
	for j in range(n):
		if b[j] == 1:
			x = j + 1
		if b[n - j - 1] == 1:
			y = j + 1
	if b[0] == 1 or b[n - 1] == 1:
		print(n * 2)
	elif x >= y and sum(b) != 0:
		print(x * 2)
	elif y > x and sum(b) != 0:
		print(y * 2)
	else:
		print(n)


for iteri in range(int(input())):
	n = int(input())
	array = list(map(int, input()))
	ones = []
	for i in range(len(array)):
		if array[i] == 1:
			ones.append(i)
	if len(ones) == 0:
		print(n)
	elif ones[0] == 0 or ones[-1] == n - 1:
		print(2 * n)
	elif len(ones) == 1:
		print(2 * (max(ones[0], n - 1 - ones[0]) + 1))
	else:
		print(2 * (max(ones[0], n - 1 - ones[0], ones[-1], n - 1 - ones[-1]) + 1))


from sys import stdin
from math import ceil
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input()
	if s[0] == '1' or s[n - 1] == '1':
		print(2 * n)
	elif '1' in s:
		ans = 0
		cnt = s.count('1')
		for i in range(n):
			if s[i] == '0':
				ans += 2
			else:
				ans += 2
				cnt -= 1
				if not cnt:
					break
		ans2 = 0
		cnt = s.count('1')
		for i in range(n):
			if s[n - i - 1] == '0':
				ans2 += 2
			else:
				ans2 += 2
				cnt -= 1
				if not cnt:
					break
		print(max(ans, ans2))
	else:
		print(n)


t = int(input())
while t:
	n = int(input())
	a = input()
	left = 0
	right = 0
	if a.find('1') >= 0:
		left = n - a.find('1')
	if a.rfind('1') >= 0:
		right = a.rfind('1') + 1
	if left or right:
		print(2 * max(left, right))
	else:
		print(n)
	t = t - 1


t = int(input())
for _ in range(t):
	n = int(input())
	p = list(map(int, list(input())))
	if 1 in p:
		if p[0] == 1 or p[-1] == 1:
			print(2 * n)
		else:
			z = p.index(1)
			p.reverse()
			z1 = p.index(1)
			print(2 * (n - min(z, z1)))
	else:
		print(n)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	if s[0] == '1' or s[-1] == '1':
		print(2 * n)
	else:
		count = s.count('1')
		if count >= 1:
			left = s.find('1')
			right = s.rfind('1')
			print(max(2 * (len(s) - left), 2 * (right + 1), n + count))
		else:
			print(n)


def rooms(n, s):
	maxx = n
	for i in range(n):
		if s[i] == '1':
			maxx = max((n - i) * 2, maxx)
			break
	for (j, e) in enumerate(s[::-1]):
		if e == '1':
			maxx = max((n - j) * 2, maxx)
			break
	print(maxx)
for i in range(int(input())):
	n = int(input())
	s = input()
	rooms(n, s)


for _ in range(int(input())):
	n = int(input())
	s = input()
	f = 0
	if s[0] == '1' or s[n - 1] == '1':
		print(2 * n)
		f = 1
	else:
		for i in range(0, n):
			if s[i] == '1':
				m = max(i + 1, n - i)
				print(2 * m)
				f = 1
				break
			elif s[n - i - 1] == '1':
				m = max(i + 1, n - i)
				print(2 * m)
				f = 1
				break
	if f == 0:
		print(n)


for _ in range(int(input())):
	sizee = int(input())
	strr = input()
	if '1' not in strr:
		print(sizee)
	else:
		first = sizee - strr.find('1')
		last = strr.rfind('1') + 1
		res = 2 * max(first, last)
		print(res)


for _ in range(int(input())):
	n = int(input())
	ln = input()
	ans = len(ln) - ln[::-1].find('1')
	ans_rev = len(ln) - ln.find('1')
	ans = max(ans, ans_rev)
	if ans > n:
		ans = n
	elif ans < len(ln) / 2:
		ans = len(ln)
	else:
		ans *= 2
	print(ans)


import sys
readline = sys.stdin.readline
t = [int(x) for x in input().split()]
for _ in range(t[0]):
	n = [int(x) for x in input().split()]
	s = input()
	k = -1
	for i in range(len(s)):
		if s[i] == '1':
			k = i
			break
	s = s[::-1]
	for i in range(len(s)):
		if s[i] == '1':
			k = min(i, k)
			break
	if k == -1:
		print(len(s))
	else:
		print(2 * (len(s) - k))


t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	s = input()
	idx_r = -1
	idx_l = -1
	for (idx, i) in enumerate(reversed(s)):
		if i == '1':
			idx_r = idx
			break
	for (idx, i) in enumerate(s):
		if i == '1':
			idx_l = idx
			break
	if idx_r == -1 and idx_l == -1:
		print(n)
	else:
		idx_r = n - idx_r
		idx_l = n - idx_l
		a = 2 * idx_r
		b = 2 * idx_l
		print(max(n, a, b))


n = int(input())
a = list()
for i in range(n):
	r = input()
	s = input()
	a.append(s)

def f(x):
	if '1' in x:
		for i in range(len(x)):
			if x[i] == '1':
				max = i + 1
		max1 = 2 * max
		for i in range(1, len(x) + 1):
			if x[-i] == '1':
				max = i
		max2 = 2 * abs(max)
		if max1 > max2:
			return max1
		return max2
	return len(x)
for i in range(n):
	print(f(a[i]))


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, list(input())))
	if r[0] == 1 or r[n - 1] == 1:
		print(2 * n)
	else:
		l = n
		for i in range(n):
			if r[i] == 1:
				l = i
				break
		right = -1
		for i in range(n - 1, -1, -1):
			if r[i] == 1:
				right = i
				break
		print(max(n + sum(r), 2 * (n - l), 2 * (right + 1)))


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	n = int(input())
	s = input().strip()
	ans = n
	ones = [i + 1 for i in range(n) if s[i] == '1']
	try:
		mn = min(ones)
		mx = max(ones)
		x = n - mn + 1
		y = mx
		ans = 2 * max(x, y)
		print(ans)
	except:
		print(ans)


t = int(input())
while t > 0:
	n = int(input())
	x = input()
	rightind = -1
	leftind = -1
	for i in range(0, n):
		if x[i] == '1':
			rightind = i
	for i in range(0, n):
		if x[n - i - 1] == '1':
			leftind = i
	if leftind == -1 and rightind == -1:
		print(n)
	elif rightind + 1 >= leftind + 1:
		print(2 * (rightind + 1))
	else:
		print(2 * (leftind + 1))
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	res = 0
	if s.count('1') == 0:
		res = n
	elif s[0] == '1' or s[-1] == '1':
		res = 2 * n
	else:
		i = s.find('1')
		j = s.rfind('1')
		res = 2 * max(i + 1, n - i, j + 1, n - j)
	print(res)


import math
q = int(input())
while q:
	n = int(input())
	s = input()
	if s[0] == '1' or s[n - 1] == '1':
		print(2 * n)
	else:
		count = 0
		for i in s:
			if i == '0':
				count = count + 1
			else:
				count = count + 2
		cnt1 = 0
		cnt2 = 0
		for j in range(0, n):
			if s[j] == '1':
				cnt1 = j
				break
		for j in range(0, n):
			if s[n - j - 1] == '1':
				cnt2 = j
				break
		f = min(cnt1, cnt2)
		if f == 0:
			print(n)
		else:
			print(max(count, (n - f) * 2))
	q = q - 1


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	s = str(input())
	ok = 0
	i = 0
	for i in range(0, n):
		if s[i] == '1' or s[n - i - 1] == '1':
			ok = 1
			ans = 2 * (n - i)
			break
	if not ok:
		ans = n
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	straight_arr = [i + 1 for i in range(n) if s[i] == '1']
	rev_arr = [n - i + 1 for i in straight_arr]
	try:
		print(max(2 * max(straight_arr), 2 * max(rev_arr)))
	except Exception:
		print(n)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	(l, r) = (0, 0)
	for i in range(n):
		if s[i] == '1':
			l = i + 1
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			r = i + 1
			break
	if r == l == 0:
		print(n)
	else:
		d = max(n - l + 1, r)
		print(d * 2)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	l = n
	h = -1
	for i in range(n):
		if s[i] == '1':
			l = min(i, l)
			h = i
	if h == -1:
		print(n)
	else:
		print(max(h + 1, n - l) * 2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if '1' in s:
		i = s.index('1')
		s2 = list(reversed(s))
		j = s2.index('1')
		print(max((i + 1) * 2, (n - i) * 2, (j + 1) * 2, (n - j) * 2))
	else:
		print(n)


import math
x = int(input())
for _ in range(x):
	n = int(input())
	s = input()
	mins = -1
	maxs = -1
	for i in range(n):
		if s[i] == '1':
			if mins < 0:
				mins = i
			maxs = i
	if maxs == -1 and mins == -1:
		print(str(n))
	else:
		print(str(2 * max(n - mins, maxs + 1)))
1


import sys
import math
input = sys.stdin.readline
big_number = 10000000
t = int(input())
for i in range(0, t):
	n = int(input())
	max_result = n
	s = input()
	for i in range(0, n):
		if s[i] == '1':
			cur_result = 2 * max(n - i, i + 1)
			max_result = max(max_result, cur_result)
	print(max_result)


q = int(input())
for rwer in range(q):
	n = int(input())
	s = input()
	p = -1
	k = -1
	for i in range(n):
		if s[i] == '1':
			p = i
			break
	for i in range(n):
		if s[i] == '1':
			k = i
	if p < 0:
		print(n)
	else:
		print(2 * n - 2 * min(p, n - k - 1))


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

def solve():
	N = int(input())
	S = input()[:-1]
	ans = N
	if any([c == '1' for c in S]):
		left_most = float('inf')
		right_most = -1
		for (i, c) in enumerate(S):
			if c == '1':
				left_most = min(left_most, i)
				right_most = max(right_most, i)
		ans = max(N * 2 - min(N - right_most - 1, left_most) * 2, N)
	print(ans)
T = int(input())
for _ in range(T):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	x = [int(i) for i in list(input())]
	(ix, jx, j) = (-1, -1, 0)
	while (ix == -1 or jx == -1) and j < n:
		if x[j] == 1 and ix == -1:
			ix = j
		if x[-j - 1] == 1 and jx == -1:
			jx = j
		j += 1
	if ix == -1:
		print(n)
	else:
		p = n - ix - jx
		if ix < jx:
			(ix, jx) = (jx, ix)
		print(2 * (p + ix))


for _ in range(int(input())):
	n = int(input())
	s = input()
	if s[0] == '1' or s[-1] == '1':
		print(n * 2)
	else:
		a = s.find('1')
		b = s[::-1].find('1')
		if b < a:
			a = b
		if a == -1:
			print(n)
		else:
			print((n - a) * 2)


from sys import stdin, stdout
import heapq
import cProfile, math
from collections import Counter, defaultdict, deque
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
import sys
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)
fac_warm_up = False
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n
		self.lista = [[_] for _ in range(n)]

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]
		self.lista[a] += self.lista[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def prime_factors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def all_factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def fibonacci_modP(n, MOD):
	if n < 2:
		return 1
	return (cached_fn(fibonacci_modP, (n + 1) // 2, MOD) * cached_fn(fibonacci_modP, n // 2, MOD) + cached_fn(fibonacci_modP, (n - 1) // 2, MOD) * cached_fn(fibonacci_modP, (n - 2) // 2, MOD)) % MOD

def factorial_modP_Wilson(n, p):
	if p <= n:
		return 0
	res = p - 1
	for i in range(n + 1, p):
		res = res * cached_fn(InverseEuler, i, p) % p
	return res

def binary(n, digits=20):
	b = bin(n)[2:]
	b = '0' * (digits - len(b)) + b
	return b

def is_prime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True

def generate_primes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	return prime
factorial_modP = []

def warm_up_fac(MOD):
	nonlocal factorial_modP, fac_warm_up
	if fac_warm_up:
		return
	factorial_modP = [1 for _ in range(fac_warm_up_size + 1)]
	for i in range(2, fac_warm_up_size):
		factorial_modP[i] = factorial_modP[i - 1] * i % MOD
	fac_warm_up = True

def InverseEuler(n, MOD):
	return pow(n, MOD - 2, MOD)

def nCr(n, r, MOD):
	nonlocal fac_warm_up, factorial_modP
	if not fac_warm_up:
		warm_up_fac(MOD)
		fac_warm_up = True
	return factorial_modP[n] * (pow(factorial_modP[r], MOD - 2, MOD) * pow(factorial_modP[n - r], MOD - 2, MOD) % MOD) % MOD

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return list(map(int, stdin.readline().split()))

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	nonlocal memory
	memory = dict()

def cached_fn(fn, *args):
	nonlocal memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result

def ncr(n, r):
	return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

def binary_search(i, li):
	fn = lambda x: li[x] - x // i
	x = -1
	b = len(li)
	while b >= 1:
		while b + x < len(li) and fn(b + x) > 0:
			x += b
		b = b // 2
	return x
TestCases = True
optimise_for_recursion = True

def main():
	n = get_int()
	li = list(stdin.readline().strip())
	x = 10 ** 10
	for (i, ele) in enumerate(li):
		if ele == '1':
			x = min(n - i - 1, i, x)
	if x == 10 ** 10:
		print(n)
	else:
		print(2 * (n - x))
if TestCases:
	for i in range(get_int()):
		main()
else:
	main() if not optimise_for_recursion else threading.Thread(target=main).start()


k = int(input())
for i in range(k):
	n = int(input())
	a = input()
	first = a.find('1')
	if first == -1:
		print(n)
		continue
	elif first == 0:
		print(n * 2)
		continue
	elif first < n - first - 1:
		first = n - first - 1
	last = a.rfind('1')
	if last < n - last - 1:
		last = n - last - 1
	if first > last:
		print((first + 1) * 2)
	else:
		print((last + 1) * 2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	f = l = -1
	for i in range(n):
		if s[i] == '1':
			f = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			l = i
			break
	if f == -1:
		print(n)
		continue
	fm = max(n - f, f + 1)
	fl = max(n - l, l + 1)
	print(2 * max(fl, fm))


import sys
input = sys.stdin.readline
t = int(input())
for testcases in range(t):
	n = int(input())
	S = input().strip()
	ANS = n
	if '1' in S:
		t = S.index('1')
		ANS = max(ANS, (n - t) * 2)
		t = S[::-1].index('1')
		ANS = max(ANS, (n - t) * 2)
	print(ANS)


t = int(input())
for i in range(t):
	r = int(input())
	s = input()
	if '1' not in s:
		print(r)
	else:
		left = s.find('1')
		right = s[::-1].find('1')
		pos = min(left, right)
		print((r - pos) * 2)


amount = int(input())
for i in range(amount):
	n = int(input())
	string = input()
	if string[0] == '1' or string[-1] == '1':
		print(2 * n)
	else:
		idx_r = string.rfind('1')
		idx_l = string.find('1')
		if idx_l == -1 and idx_r == -1:
			print(n)
		else:
			if idx_l != -1:
				left = (n - idx_l) * 2
			else:
				left = -1
			if idx_r != -1:
				right = (idx_r + 1) * 2
			else:
				right = -1
			print(max(right, left))


t = int(input())
for _ in range(t):
	n = int(input())
	e = 0
	s = 0
	stair = input()
	for i in range(len(stair)):
		if stair[i] == '1':
			s = max(s, i + 1)
			e = max(e, n - i)
	g = max(s, e)
	if g == 0:
		print(n)
	else:
		print(max(2 * g, n))


n = int(input())
a = []
for i in range(0, n):
	nn = int(input())
	s = input()
	t = -1
	tt = -1
	for j in range(0, nn):
		if s[j] == '1':
			t = j
			break
	for j in reversed(range(nn)):
		if s[j] == '1':
			tt = j
			break
	if t > -1 and nn - t > tt:
		a.append(int(nn - t) * 2)
	elif tt > -1:
		a.append(int(tt + 1) * 2)
	else:
		a.append(nn)
for i in range(0, len(a)):
	print(a[i])


from math import *
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = input()
	a = list(a)
	if a.count('1') == 0:
		print(n)
		continue
	p = n - a.index('1')
	a = a[::-1]
	q = n - a.index('1')
	print(max(p, q) * 2)


import math
t = int(input())
for j in range(t):
	n = int(input())
	s = input()
	try:
		i1 = n - s.index('1')
		i2 = s.rindex('1') + 1
		print(max(i1 * 2, i2 * 2))
	except:
		print(n)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	(first, last) = (0, 0)
	for i in range(n):
		if a[i] == '1':
			first = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == '1':
			last = i
			break
	if a[last] == '0':
		print(n)
	else:
		mx = min(first, n - 1 - last)
		print(2 * (n - mx))


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
t = ip()
for i in range(t):
	n = ip()
	s = input()
	if s.count('1') == 0:
		print(n)
	else:
		(a, b) = (s.index('1'), s[::-1].index('1'))
		print(2 * (n - min(a, b)))


n = int(input())
for _ in range(n):
	size = int(input())
	st = input()
	if st[0] == '1' or st[-1] == '1':
		print(size * 2)
	else:
		c = 0
		for i in st:
			if i == '1':
				c += 1
		if c == 0:
			print(size)
		else:
			for i in range(size):
				if size - i < i:
					break
				if st[i] == '1' or st[size - 1 - i] == '1':
					print(size * 2 - i * 2)
					break


for _ in ' ' * int(input()):
	a = int(input())
	b = input()
	print(*([max(b.rindex('1') + 1, a - b.index('1')) * 2] if b.count('1') else [a]))


(I, l) = (input, len)
for i in '0' * int(I()):
	I()
	s = I()
	print(2 * max(l(s.rstrip('0')), l(s.lstrip('0'))) or l(s))


tests = int(input())
for _ in range(tests):
	n = int(input())
	string = str(input())
	el1 = n - string.index('1') - 1 if string.count('1') > 0 else None
	el2 = n - string[::-1].index('1') - 1 if string.count('1') > 0 else None
	if el1 is None:
		print(n)
	else:
		max_element = el1 if el1 > el2 else el2
		print((max_element + 1) * 2)


n = int(input())
for a in range(n):
	x = int(input())
	y = [*input()]
	c = y[0]
	l = y.copy()
	l.reverse()
	b = l[0]
	(i, j) = (0, 0)
	s = x * ['0']
	if s == y:
		print(x)
	else:
		while c == '0' and i < x - 1:
			c = y[i + 1]
			i = i + 1
		while b == '0' and j < x - 1:
			b = l[j + 1]
			j = j + 1
		print(2 * max(x - i, x - j))


import sys
sys.setrecursionlimit(10 ** 9)

def dfs(v, cnt):
	global used, g, res
	used[v] = True
	res = max(res, cnt)
	for u in g[v]:
		if not used[u]:
			dfs(u, cnt + 1)
	return cnt
t = int(input())
for _ in range(t):
	n = int(input())
	g = [[] for l in range(2 * n)]
	i = 0
	res = 0
	for e in map(int, input()):
		if 0 < i < n - 1:
			g[i].append(i - 1)
			g[i].append(i + 1)
			g[n + i].append(n + i - 1)
			g[n + i].append(n + i + 1)
		elif i == 0 and n != 1:
			g[0].append(1)
			g[n].append(n + 1)
		elif i == n - 1 and n != 1:
			g[n - 1].append(n - 2)
			g[2 * n - 1].append(2 * n - 2)
		if e == 1:
			g[i].append(n + i)
			g[n + i].append(i)
		i += 1
	used = [False] * 2 * n
	dfs(0, 1)
	used = [False] * 2 * n
	dfs(n - 1, 1)
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = a[::-1]
	c = []
	d = a.find('1')
	e = b.find('1')
	if d == -1:
		d = n
		e = n
	c.append(2 * (n - d))
	c.append(2 * (n - e))
	c.append(n + a.count('1'))
	print(max(c))


t = int(input())
(sz, ly) = (list(), list())
rqd = 0
ctr1 = 0
ctr2 = 0
for i in range(t):
	sz.append(int(input()))
	ly.append(str(input()))
for i in range(t):
	for j in range(len(ly[i])):
		if ly[i][-(j + 1)] == '0':
			ctr1 += 1
		else:
			break
	for j in range(len(ly[i])):
		if ly[i][j] == '0':
			ctr2 += 1
		else:
			break
	if ctr1 > ctr2:
		l = ly[i][::-1]
	else:
		l = ly[i]
	for j in range(len(l)):
		if l[j] == '1':
			rqd = j + 1
	if len(l) > 2 * (rqd - 1) and rqd != 0:
		print(len(l) + 1)
	elif rqd == 0:
		print(len(l))
	else:
		print(2 * rqd)
	rqd = 0
	(ctr1, ctr2) = (0, 0)


import math
t = int(input())
for q in range(t):
	n = int(input())
	s = input()
	ind = []
	for i in range(n):
		if s[i] == '1':
			ind.append(i)
	if len(ind) > 0:
		print(max((ind[len(ind) - 1] + 1) * 2, (n - ind[0]) * 2))
	else:
		print(n)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	e = s.find('1')
	r = s.rfind('1')
	if r != -1:
		print(max((r + 1) * 2, (n - e) * 2, n))
	else:
		print(n)


for t in range(int(input())):
	n = int(input())
	s = input()
	l = s.find('1')
	r = s.rfind('1')
	if l == r == -1:
		print(n)
		continue
	dist = max(l + 1, r + 1, n - l, n - r)
	print(2 * dist)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, list(input())))
	ans = 0
	for i in range(1, n + 1):
		if s[i - 1]:
			ans = max(ans, 2 * i)
	s = s[::-1]
	for i in range(1, n + 1):
		if s[i - 1]:
			ans = max(ans, 2 * i)
	print(max(ans, n + sum(s)))


import sys
import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True
t = ii()
for i in range(t):
	n = ii()
	s = input()
	if '1' not in s:
		print(n)
	else:
		print(2 * max(s.rfind('1') + 1, n - s.find('1')))


for i in range(int(input())):
	n = input()
	n = input()
	LN0 = 0
	LN1 = 0
	if n[0] != n[len(n) - 1]:
		print(len(n) * 2)
	elif len(set(n)) == 1 and n[0] == '0':
		print(len(n))
	else:
		i = 1
		while n[i - 1:i] == '0' and i <= len(n):
			LN0 += 1
			i += 1
		i = 1
		n = n[::-1]
		while n[i - 1:i] == '0' and i <= len(n):
			LN1 += 1
			i += 1
		if LN0 > LN1:
			print((len(n) - LN1) * 2)
		else:
			print((len(n) - LN0) * 2)


T = int(input())
for _ in range(T):
	N = int(input())
	S = input()
	if S.count('1') == 0:
		print(N)
	else:
		x = S.index('1')
		y = S[::-1].index('1')
		print(max(N - x, N - y) * 2)


t = int(input())
for i in range(0, t):
	n = int(input())
	s = str(input())
	a = s.rfind('1')
	b = s.find('1')
	ans = max(a, b)
	if ans < 0:
		print(n)
	else:
		b = n - b
		a += 1
		ans = max(a, b)
		print(2 * ans)


for _ in range(int(input())):
	n = int(input())
	a = str(input())
	k1 = a.find('1')
	k2 = a.rfind('1')
	if k1 <= n - k2 - 1:
		k = k1
	else:
		k = k2
	if a.find('1') == -1:
		print(n)
	else:
		print(max(k + 1, abs(n - k)) * 2)


for i in range(int(input())):
	n = int(input())
	s = list(input())
	room_r = -1
	room_l = -1
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			room_r = j
			break
	for j in range(n):
		if s[j] == '1':
			room_l = j
			break
	if room_r == -1 and room_l == -1:
		print(n)
	else:
		if room_l >= n // 2 and room_r >= n // 2:
			m = 2 * (room_r + 1)
		elif room_l < n // 2 and room_r < n // 2:
			m = 2 * (n - room_l)
		elif room_l < n // 2 and room_r >= n // 2:
			m = max(2 * (n - room_l), 2 * (room_r + 1))
		print(m)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	if a.count('1') > 0:
		print(max((n - a.find('1')) * 2, (a.rfind('1') + 1) * 2))
	else:
		print(n)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	s = input()
	if s.count('1') == 0:
		print(n)
		continue
	if s.find('1') + s.rfind('1') + 1 <= n:
		print(max(s.find('1') + 1, abs(n - s.find('1'))) * 2)
	else:
		print(max(s.rfind('1') + 1, abs(n - s.rfind('1'))) * 2)


for i in range(int(input())):
	w = int(input())
	e = input()
	if '1' in e:
		r = min(e.index('1'), e[::-1].index('1'))
		print(2 * (w - r))
	else:
		print(w)


x = int(input())
for n in range(x):
	a = int(input())
	p = []
	k = input()
	for y in range(a):
		if k[y] == '1':
			p.append(y)
	if len(p) == 0:
		print(a)
	elif k[0] == '1' or k[a - 1] == '1':
		print(2 * a)
	else:
		o = min(p)
		l = max(p)
		g = max(l, a - o - 1)
		print(2 * g + 2)


def solve():
	n = int(input())
	s = input()
	ans = n
	for i in range(n):
		if s[i] == '1':
			d = max(i + 1, n - i)
			ans = max(ans, 2 * d)
	return ans

def main():
	t = int(input())
	for _ in range(t):
		print(solve())
main()


CASES = int(input())
for _ in range(CASES):
	n = int(input())
	s = input()
	min1 = 0
	max1 = 0
	flagmin = False
	for i in range(n):
		if s[i] == '1':
			if not flagmin:
				min1 = i + 1
				flagmin = True
			if i + 1 > max1:
				max1 = i + 1
	if min1 == max1 == 0:
		print(n)
	else:
		a = max(n - min1 + 1, n - max1 + 1, min1, max1)
		print(2 * a)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	least_index1 = -1
	least_index2 = 0
	for i in range(n):
		if s[i] == '1':
			least_index1 = i
			break
	for i in range(-1, -n - 1, -1):
		if s[i] == '1':
			least_index2 = i
			break
	ans1 = 2 * max(n - least_index1, least_index1 + 1) if least_index1 != -1 else n
	ans2 = 2 * max(n + least_index2 + 1, -least_index2) if least_index2 != 0 else n
	print(max(ans1, ans2))


for _ in range(int(input())):
	n = int(input())
	s = input()
	a = 0
	for i in range(len(s)):
		if s[i] == '1':
			a = max(a, (i + 1) * 2, (n - i) * 2)
	y = n + s.count('1')
	print(max(y, a))


for _ in range(int(input())):
	n = int(input())
	l = ' '.join(input())
	l1 = list(map(int, l.split()))
	if 1 in l1:
		x = n - l1.index(1)
		y = n - l1[::-1].index(1)
		print(max(x * 2, y * 2))
	else:
		print(n)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if s[-1] == 1 or s[0] == 1:
		print(2 * n)
		continue
	ind = [i for (i, x) in enumerate(s) if x == '1']
	ind2 = [n - x - 1 for (i, x) in enumerate(ind)]
	if len(ind) == 0:
		print(n)
		continue
	m1 = (max(ind) + 1) * 2
	m2 = (max(ind2) + 1) * 2
	if m1 > m2:
		print(m1)
	else:
		print(m2)


t = int(input())
for i in range(t):
	n = int(input())
	stairs = input()
	if stairs == n * '0':
		print(n)
	elif stairs[0] == '1' or stairs[-1] == '1':
		print(n * 2)
	else:
		direction = 0
		ones = [pos for (pos, char) in enumerate(stairs) if char == '1']
		if ones[-1] > n - 1 - ones[0]:
			print((ones[-1] + 1) * 2)
		else:
			print((n - ones[0]) * 2)


t = int(input())
while t != 0:
	n = int(input())
	string = input()
	leftmost_one = n + 2
	rightmost_one = -1
	for i in range(n):
		if string[i] == '1':
			if leftmost_one > i:
				leftmost_one = i
			if rightmost_one < i:
				rightmost_one = i
	if rightmost_one == -1:
		print(n)
	else:
		leftmost_one += 1
		rightmost_one += 1
		print(max(2 * rightmost_one, 2 * (n - leftmost_one + 1)))
	t -= 1


I = input
for _ in range(int(I())):
	(n, s) = (int(I()), I())
	print(max(n, 2 * max(len(s.lstrip('0')), len(s.rstrip('0')))))


n = int(input())
for i in range(n):
	k = int(input())
	a = input()
	if '1' in a:
		print(2 * max(k - a.index('1'), k - a[::-1].index('1')))
	else:
		print(k)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 1000000007
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	s = input()
	ans = 0
	for i in range(n):
		rooms = max(i + 1, n - i)
		if s[i] == '1':
			rooms *= 2
		ans = max(ans, rooms)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	f = 0
	e = 0
	for i in range(n):
		if s[i] == '1':
			break
		f += 1
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			break
		e += 1
	ans = max(n, max(2 * n - 2 * f, 2 * n - 2 * e))
	print(ans)


def ans(s):
	n = len(s)
	x = s.find('1')
	if x == -1:
		return n
	y = s.rfind('1')
	return max(n, 2 * (n - x), 2 * (y + 1))
for i in range(int(input())):
	n = input()
	s = input()
	print(ans(s))


def solve():
	n = int(input())
	s1 = input()
	i = 0
	val = 0
	while i < len(s1):
		if s1[i] == '1':
			val = max(2 * max(n - i, i + 1), val)
		i += 1
	print(max(val, n))
t = int(input())
for i in range(t):
	solve()


testi = int(input())
for i in range(testi):
	n = int(input())
	trepes = input()
	if trepes.count('1') == 0:
		print(n)
		continue
	kreisa = trepes.index('1')
	ds = list(reversed(trepes))
	laba = ds.index('1')
	if kreisa > laba:
		print((n - laba) * 2)
	if kreisa <= laba:
		print((n - kreisa) * 2)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if s.find('1') > -1:
		res = max(n - s.find('1'), s.rfind('1') + 1) * 2
	else:
		res = len(s)
	print(res)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if '1' in s:
		(l, r) = (s.index('1'), s.rindex('1'))
		print(2 * (max(l, n - l - 1, r, n - r - 1) + 1))
	else:
		print(n)


for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input()))
	if 1 in ar:
		x = ar.index(1)
		ar.reverse()
		y = ar.index(1)
		if x == n - y - 1:
			print(max(x + 1, n - x) * 2)
		else:
			print(max((n - y) * 2, (n - x) * 2))
	else:
		print(n)


t = int(input())
for i in range(t):
	n = int(input())
	s = str(input())
	if s.count('1') == 0:
		print(n)
	else:
		k = s.index('1') + 1
		s = s[::-1]
		l = len(s) - s.index('1')
		print(2 * max(k, l, len(s) - k + 1, l))


t = int(input())
m = []
for i in ' ' * t:
	b = int(input())
	s = input()
	p1 = s.rfind('1')
	p2 = b - s.find('1') - 1
	p = max(p1, p2)
	if p1 == -1:
		r = b
	else:
		r = p + 1
		y = b - 1 - p
		if y < b - 1 - y:
			y = b - 1 - y
		r += y + 1
	m += [r]
for i in m:
	print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if '1' not in s:
		print(n)
	else:
		lindex = s.index('1') + 1
		rindex = s.rindex('1') + 1
		print(max(rindex + max(rindex, n - rindex + 1), n - lindex + 1 + max(lindex, n - lindex + 1)))


for x in range(int(input())):
	n = int(input())
	l = list(input())
	a = []
	for y in range(n):
		if l[y] == '1':
			a.append(max(y + 1, n - y))
	if a == []:
		print(n)
	else:
		print(2 * max(a))


T = int(input())
for t in range(0, T):
	n = int(input())
	st = input()
	s = st.find('1')
	if s == -1:
		print(n)
		continue
	e = st.rfind('1') + 1
	s = max(abs(n - s), s)
	e = max(abs(n - e), e)
	print(max(s, e) * 2)


tets = int(input())
for x in range(tets):
	floor = int(input())
	array = input()
	if array[0] == '1' or array[-1] == '1':
		print(floor * 2)
	else:
		index = []
		y = 0
		while y < floor:
			if array[y] == '1':
				index.append(y)
			y += 1
		if index == list():
			print(floor)
		else:
			before = index[0]
			after = floor - index[-1] - 1
			maxx = max(before, after) * 2
			diff = index[-1] - index[0] + 1
			print(maxx + diff * 2)


t = int(input())
for i in range(t):
	n = int(input())
	moves = input()
	if '1' in moves:
		(il, ir) = (moves.find('1'), moves.rfind('1'))
		if il + 1 < n - ir:
			(il, ir) = (n - ir - 1, n - il - 1)
		print(max((ir + 1) * 2, n))
	else:
		print(n)


n = int(input())
m1 = 0
m2 = 0
for i in range(n):
	x = int(input())
	list1 = [int(x) for x in list(input())]
	for k in range(x):
		if list1[k] == 0:
			m1 += 1
		else:
			break
	for k in range(x):
		if list1[x - 1 - k] == 0:
			m2 += 1
		else:
			break
	print(max(x, 2 * (x - min(m1, m2))))
	m1 = 0
	m2 = 0


T = int(input())
for _ in range(0, T):
	n = int(input())
	s = input()
	ptr1 = -1
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			ptr1 = i
			break
	ptr2 = -1
	for i in range(0, len(s)):
		if s[i] == '1':
			ptr2 = i
			break
	if ptr1 == -1:
		print(n)
	else:
		ans1 = 0
		ans2 = 0
		if ptr1 + 1 > n - ptr1 - 1:
			ans1 = 2 * ptr1 + 2
		else:
			ans1 = n
		if n - ptr2 > ptr2:
			ans2 = 2 * n - 2 * ptr2
		else:
			ans2 = n
		print(max(ans1, ans2))


def room(n, s):
	z = y = k = f = x = u = 0
	li = []
	for i in range(n):
		if s[0] == '1' or s[-1] == '1':
			f = 2 * n
			li.append(f)
		if s[i] == '1':
			z = i + 1 + (n - i)
			y = 2 * (n - i)
			x = 2 * (i + 1)
			u = max(x, y, z)
			li.append(u)
		if s[i] == '0':
			k += 1
			i += 1
			li.append(k)
	return max(li)
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ans = room(n, s)
	print(ans)


from sys import stdin, stdout
from collections import Counter
import math

def rsingle_int():
	return int(stdin.readline().rstrip())

def rmult_int():
	return [int(x) for x in stdin.readline().rstrip().split()]

def rmult_str():
	return stdin.readline().rstrip().split()

def r_str():
	return stdin.readline().rstrip()

def rsingle_char():
	return stdin.read(1)

def sortFirst(val):
	return val[0]

def main():
	t = rsingle_int()
	for _ in range(t):
		num_rooms = rsingle_int()
		stairs = r_str()
		llast = stairs.rfind('1')
		rlast = stairs.find('1')
		if llast == -1:
			print(num_rooms)
		else:
			print(max((llast + 1) * 2, (num_rooms - rlast) * 2))
main()


def main_function():
	input_data = [[int(input()), input()] for i in range(int(input()))]
	for i in input_data:
		(n, s) = i
		max_val = n
		for i in range(len(s)):
			if s[i] == '1':
				if max_val < 2 * max(i + 1, n - i):
					max_val = 2 * max(i + 1, n - i)
		print(max_val)
main_function()


t = int(input())
for i in range(t):
	n = int(input())
	s = str(input())
	if s == '0' * n:
		print(n)
	else:
		for j in range(len(s)):
			if s[j] == '1':
				m1 = j + 1
				break
		for k in range(1, len(s) + 1):
			if s[-k] == '1':
				m2 = k
				break
		m = min(m1, m2)
		ans = 2 * abs(n - m + 1)
		print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = list(a)
	if b.count('1'):
		c = b[::-1]
		x = b.index('1')
		y = c.index('1')
		z = min(x, y)
		print(max(2 * (n - z), 2 * z))
	else:
		print(n)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	st = -1
	end = -1
	i = 0
	for i in range(n):
		if s[i] == '1':
			if st == -1 and end == -1:
				st = i
				end = i
			else:
				end = i
	if st == -1:
		print(n)
	else:
		print(2 * max(n - st, end + 1))


for _ in range(int(input())):
	n = int(input())
	arr = list(input())
	sm = 0
	if arr.count('0') == n:
		sm = n
		[]
	else:
		for i in range(n):
			if arr[i] == '1':
				sm = max(sm, 2 * (i + 1), 2 * (n - i))
	print(sm)


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	floor = str(input())
	j = n
	for i in range(n // 2 + 1):
		if floor[i] == '1' or floor[n - i - 1] == '1':
			j = 2 * (n - i)
			break
	ans.append(j)
for i in range(t):
	print(ans[i])


q = int(input())
for i in range(q):
	n = int(input())
	lst1 = list(input())
	if lst1[0] == '1' or lst1[len(lst1) - 1] == '1':
		print(n * 2)
	else:
		count1 = lst1.count('1')
		count0 = lst1.count('0')
		res1 = count1 * 2 + count0 * 1
		pos1 = -1
		pos2 = -1
		res2 = 0
		res3 = 0
		for i in range(len(lst1)):
			if lst1[i] == '1':
				pos1 = i
				break
		for i in range(len(lst1) - 1, -1, -1):
			if lst1[i] == '1':
				pos2 = i
				break
		if pos1 != -1:
			res2 = max(abs(n - pos1), pos1) * 2
		if pos2 != -1:
			pos2 += 1
			res3 = max(abs(n - pos2), pos2) * 2
		print(max(res1, res2, res3))


def main():
	import sys
	t = int(input())
	for __ in [0] * t:
		n = int(input())
		s = input()
		a = [0] * n
		b = [0] * n
		a[0] = 1
		if s[0] != '0':
			a[0] = b[0] = 2
		for i in range(1, n):
			if s[i] == '0':
				a[i] = a[i - 1] + 1
				if b[i - 1] != 0:
					b[i] = b[i - 1] + 2
			else:
				a[i] = a[i - 1] + 2
				b[i] = b[i - 1] + 2
		res = max(a[-1], b[-1])
		s = s[::-1]
		a = [0] * n
		b = [0] * n
		a[0] = 1
		if s[0] != '0':
			a[0] = b[0] = 2
		for i in range(1, n):
			if s[i] == '0':
				a[i] = a[i - 1] + 1
				if b[i - 1] != 0:
					b[i] = b[i - 1] + 2
			else:
				a[i] = a[i - 1] + 2
				b[i] = b[i - 1] + 2
		res = max(res, a[-1], b[-1])
		print(res)
main()


import math

def main():
	t = int(input())
	for test in range(t):
		n = int(input())
		rooms = input()
		stair = -1
		lastfinal = -1
		for i in range(len(rooms)):
			if rooms[i] == '1':
				final = max(i, n - i - 1)
				if final > lastfinal:
					lastfinal = final
					stair = i
		if lastfinal == -1:
			print(n)
		else:
			print((lastfinal + 1) * 2)
main()


number_of_test_cases = int(input())
number_of_rooms = []
staircase_order = []
for i in range(0, number_of_test_cases):
	number_of_rooms.append(int(input()))
	staircase_order.append(input())
for i in range(0, number_of_test_cases):
	forward = 0
	backward = 0
	mid_point = number_of_rooms[i] // 2
	steps = 0
	if number_of_rooms[i] % 2 == 1:
		mid_point = number_of_rooms[i] // 2 + 1
	for j in range(0, mid_point):
		if staircase_order[i][j] == '1':
			forward = number_of_rooms[i] - j
			break
	reversed_staircase_order = staircase_order[i][::-1]
	for j in range(0, mid_point):
		if reversed_staircase_order[j] == '1':
			backward = number_of_rooms[i] - j
			break
	if forward == 0 and backward == 0:
		steps = number_of_rooms[i]
	elif forward >= backward:
		steps = forward * 2
	else:
		steps = backward * 2
	print(steps)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	N = int(input())
	g = list(map(int, input().rstrip()))
	ans = N
	for i in range(N):
		if g[i]:
			k = max(i + 1, N - i)
			ans = max(ans, k * 2)
	print(ans)


def maximum_rooms(n, s):
	if s[0] == '1' or s[-1] == '1':
		return n * 2
	elif '1' not in s:
		return n
	else:
		stair_left = 0
		stair_right = 0
		rooms = 0
		for x in range(n - 1, -1, -1):
			if s[x] == '1':
				stair_left = x + 1
				break
		for y in range(n):
			if s[y] == '1':
				stair_right = n - y
				break
		if stair_left > stair_right:
			if n - stair_left + 1 > stair_left:
				for x in range(stair_left):
					if s[x] == '1':
						rooms += 2
					else:
						rooms += 1
				rooms += n - stair_left + 1
			else:
				rooms += stair_left * 2
		else:
			s = s[::-1]
			if n - stair_right + 1 > stair_right:
				for x in range(stair_right):
					if s[x] == '1':
						rooms += 2
					else:
						rooms += 1
				rooms += n - stair_right + 1
			else:
				rooms += stair_right * 2
		return rooms
t = int(input())
ans = []
for x in range(t):
	n = int(input())
	s = input()
	ans.append(maximum_rooms(n, s))
for u in ans:
	print(u)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	flag = 0
	for i in range(n // 2 + 1):
		if s[i] == '1':
			flag = 1
			print(2 * (n - i))
			break
		elif s[n - i - 1] == '1':
			flag = 1
			print(2 * (n - i))
			break
	if flag == 0:
		print(n)


a = int(input())
for i in range(a):
	n = input()
	s = input()
	if s.count('0') == len(s):
		print(len(s))
	else:
		t = s.index('1')
		k = []
		k.append(t + 1)
		k.append(len(s) - t)
		al = s[::-1]
		r = al.index('1')
		k.append(r + 1)
		k.append(len(s) - r)
		print(2 * max(k))


for u in range(int(input())):
	n = int(input())
	s = input()
	r = s[::-1]
	if '1' not in s:
		print(n)
	else:
		(x, y) = (s.index('1'), r.index('1'))
		print(max(n - x, n - y) * 2)


tests = int(input())
for _ in range(tests):
	n = int(input())
	arr = list(input())
	maxDist = -1
	for i in range(n):
		if arr[i] == '0':
			continue
		index = i
		dist1 = i
		dist2 = n - i - 1
		dist = min(dist1, dist2)
		if maxDist == -1:
			maxDist = dist
		if dist < maxDist:
			maxDist = dist
	if maxDist == -1:
		print(n)
	else:
		print(2 * n - 2 * maxDist)


import sys
input = lambda : sys.stdin.readline().strip()

def dfs(i, j, visit, s):
	if not visit[i, j]:
		visit[i, j] = True
		(val1, val2, val3) = (0, 0, 0)
		if j > 0 and (not visit[i, j - 1]):
			val1 = dfs(i, j - 1, visit, s)
		if j < n - 1 and (not visit[i, j + 1]):
			val2 = dfs(i, j + 1, visit, s)
		if not visit[1 - i, j] and int(s[j]) == 1:
			val3 = dfs(1 - i, j, visit, s)
		return max(val1, val2, val3) + 1
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	visited = {}
	for i in range(2):
		for j in range(n):
			visited[i, j] = False
	M = dfs(0, 0, dict(visited), s)
	M = max(M, dfs(1, 0, dict(visited), s))
	M = max(M, dfs(0, n - 1, dict(visited), s))
	M = max(M, dfs(1, n - 1, dict(visited), s))
	print(M)


from sys import stdin
i = int(stdin.readline())
for x in range(i):
	stdin.readline()
	data = stdin.readline().rstrip()
	if data.count('1') == 0:
		print(len(data))
	else:
		left = data.index('1')
		right = list(reversed(data)).index('1')
		print((len(data) - min(left, right)) * 2)


def solve(x):
	ans = 0
	for i in range(n):
		if x[i] == '1':
			ans = max(2 * (i + 1), i + 1 + n - i)
	return ans
q = int(input())
for i in range(q):
	n = int(input())
	s = input()
	print(max(n, solve(s), solve(s[::-1])))


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = [i for i in range(n) if s[i] == '1']
	if len(l) == 0:
		print(n)
	else:
		mn = min((i for i in range(n) if s[i] == '1'))
		mx = max((i for i in range(n) if s[i] == '1'))
		ans = max(mn - 1 + 2 * (mx - mn + 1), n - mx - 1 + 2 * (mx - mn + 1), 2 * (n - mn), 2 * (mx + 1))
		if mx != mn:
			ans = max(ans, n + 2)
		print(ans)


for _ in range(int(input())):
	N = int(input())
	S = list(input())
	FLAG = 0
	for i in range(N):
		(store1, store2) = (0, 0)
		if S[i] == '1':
			store1 = (N - i) * 2
			FLAG = 1
		if S[N - 1 - i] == '1':
			store2 = (N - i) * 2
			FLAG = 1
		if FLAG == 1:
			break
	if store1 >= store2 and FLAG == 1:
		print(store1)
	elif store1 < store2 and FLAG == 1:
		print(store2)
	if FLAG == 0:
		print(N)


t = int(input())
for _ in range(t):
	n = int(input())
	rooms = input()
	f1 = rooms.find('1')
	l1 = rooms.rfind('1')
	if f1 == -1:
		print(n)
	else:
		a1 = 2 * (f1 + 1)
		a2 = 2 * (l1 + 1)
		a3 = 2 * (n - f1)
		a4 = 2 * (n - l1)
		print(max([a1, a2, a3, a4]))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	first = -1
	for j in range(len(s)):
		if s[j] == '1':
			first = j
			break
	for j in range(len(s)):
		if s[n - j - 1] == '1':
			second = j
			break
	if first == -1:
		print(n)
	else:
		print(max(2 * (n - first), 2 * (n - second)))


t = int(input())
for _ in range(t):
	n = int(input())
	string = input()
	start = n
	end = -1
	total = 0
	for i in range(len(string)):
		if string[i] == '1':
			if i <= start:
				start = i
			elif i > end:
				end = i
	if start == n:
		start = -1
	if start == 0 or end == n - 1:
		total = 2 * n
	elif start == -1 and end == -1:
		total = n
	elif start == -1 or end == -1:
		k = max(start, end)
		total = max(2 * (k + 1), 2 * (n - k))
	else:
		k = max(n - max(0, start), end + 1)
		total = 2 * k
	print(total)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	(l, r, i) = (0, n - 1, 0)
	if a.count('1') == 0:
		print(n)
	else:
		while i < n and a[i] != '1':
			i = i + 1
		l = i
		i = n - 1
		while i >= 0 and a[i] != '1':
			i = i - 1
		r = i
		p = n - 1 - l
		q = r - 0
		r = max(p, q)
		print((r + 1) * 2)


import sys
t = int(sys.stdin.readline())
arr = []
for i in range(t):
	n = int(sys.stdin.readline())
	s = sys.stdin.readline().strip()
	if s[0] == '1' or s[-1] == '1':
		arr.append(str(2 * n))
	else:
		pos = -2
		bpos = -2
		for g in range(n):
			if s[g] == '1':
				pos = g
				break
		for h in range(n - 1, -1, -1):
			if s[h] == '1':
				pos2 = h
				break
		if pos == -2:
			arr.append(str(n))
		else:
			p1 = max(pos + 1, n - pos)
			p2 = max(pos2 + 1, n - pos2)
			p = max(p1, p2)
			ans = 2 * p
			arr.append(str(ans))
print('\n'.join(arr))


from math import *
q = int(input())
for y in range(q):
	n = int(input())
	s = list(input())
	ind1 = -1
	ind2 = -1
	for i in range(n):
		if s[i] == '1':
			ind1 = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			ind2 = n - 1 - i
			break
	m = min(ind1, ind2)
	ans = 2 * (n - m)
	if ind1 == -1:
		print(n)
	else:
		print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	a = 0
	b = n - 1
	while a < n and (s[a] != '1' and s[b] != '1'):
		a += 1
		b -= 1
	if '1' not in s:
		print(n)
	elif s[a] == '1':
		print(2 * (n - a))
	elif s[b] == '1':
		print(2 * (b + 1))


import sys

def rooms_and_staircases(a):
	n = len(a)
	if a.count('1') == 0:
		print(f'{n}')
	else:
		print(f"{2 * (n - min(a.index('1'), a[::-1].index('1')))}")
for (i, line) in enumerate(sys.stdin):
	if i != 0 and i % 2 < 1:
		rooms_and_staircases(line.lstrip().rstrip())


t = int(input())
for i in range(t):
	b = int(input())
	s = input()
	if s.find('1') == -1:
		print(b)
		continue
	a = max(b - s.find('1'), s.rfind('1') + 1)
	print(2 * a)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	ans = 0
	i = 0
	f = -1
	l = -1
	while i < n:
		if s[i] == '1':
			if f == -1:
				f = i
				l = i
			else:
				l = i
		i += 1
	if f == -1:
		ans = n
	else:
		ans = max(max((f + 1) * 2, (n - f) * 2), max((l + 1) * 2, (n - l) * 2))
	print(ans)


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	(a, b) = (-1, -1)
	for k in range(n):
		if s[k] == '1':
			a = k
			break
	for k in range(n - 1, -1, -1):
		if s[k] == '1':
			b = n - 1 - k
			break
	if a == -1:
		print(n)
	else:
		print(2 * (n - min(a, b)))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		s = S()
		if '1' not in s:
			rr.append(n)
		else:
			t = n
			for (i, c) in enumerate(s):
				if c == '0':
					continue
				t = min(t, min(i, n - i - 1))
			rr.append((n - t) * 2)
	return JA(rr, '\n')
print(main())


import sys, math
tc = int(sys.stdin.readline())
for _ in range(tc):
	n = int(sys.stdin.readline())
	stair = list(map(int, sys.stdin.readline().rstrip()))
	left = 0
	for i in range(n):
		if stair[i] == 1:
			left = i + 1
	right = 0
	for i in range(n - 1, -1, -1):
		if stair[i] == 1:
			right = n - i
	if not left and (not right):
		print(n)
	else:
		print(max(2 * left, 2 * right))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip()))
	val = 0
	a = 0
	c = 0
	if n == 1:
		if arr[0] == 1:
			print('2')
		else:
			print('1')
	else:
		for i in range(n):
			if arr[i] == 1:
				a = (n - i) * 2
				c = (i + 1) * 2
				val = max(a, c, val)
		if val == 0:
			val = n
		print(val)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	if s[0] == '1' or s[-1] == '1':
		print(n * 2)
	elif n == len([c for c in s if c == '0']):
		print(n)
	else:
		print(max([max(j + 1, n - j) * 2 for j in range(n) if s[j] == '1']))


for _ in range(int(input())):
	n = int(input())
	a = input()
	x = 0
	y = n - 1
	while x < n and a[x] == '0':
		x += 1
	while y >= 0 and a[y] == '0':
		y -= 1
	if x == n:
		print(n)
	else:
		print(2 * (n - min(x, n - y - 1)))


q = int(input())
for o in range(q):
	n = int(input())
	a = list(map(int, input()))
	m = 0
	for i in range(n):
		if a[i] == 1 and max(n - i, i + 1) > m:
			m = max(n - i, i + 1)
	if m == 0:
		print(n)
	else:
		print(m * 2)


n = int(input())
for i in range(n):
	m = int(input())
	l = list(input())
	p = []
	for i in range(m):
		if l[i] == '1':
			p.append(i)
	if len(p) > 0:
		if p[0] <= m - 1 - p[-1]:
			print(2 * (m - p[0]))
		else:
			print(2 * (p[-1] + 1))
	else:
		print(m)


t = int(input())
b = [None] * t
for j in range(t):
	n = int(input())
	s = input()
	a = [None] * n
	for i in range(len(s)):
		if s[i] == '0':
			a[i] = 0
		if s[i] == '1':
			a[i] = 1
	if not 1 in a:
		b[j] = n
	else:
		k = a.index(1)
		a.reverse()
		l = a.index(1)
		if k > l:
			b[j] = 2 * (n - l)
		else:
			b[j] = 2 * (n - k)
for z in range(t):
	print(b[z])


import sys, math, queue, collections
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
for _ in range(int(input())):
	n = int(input())
	s = input()
	indx = None
	ans = n
	for i in range(n):
		if s[i] == '1':
			ans = max(ans, 2 * (n - i), 2 * (i + 1))
	print(ans)


for T in range(int(input())):
	n = int(input())
	s = input()
	if '1' not in s:
		print(n)
	else:
		lidx = n - s[::-1].index('1') - 1
		ans = lidx + 1 + max(lidx + 1, n - lidx)
		s = s[::-1]
		lidx = n - s[::-1].index('1') - 1
		ans = max(ans, lidx + 1 + max(lidx + 1, n - lidx))
		print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	bs = s[::-1]
	first_stairs = n + 1
	last_stairs = n + 1
	for i in range(len(s)):
		if s[i] == '1':
			first_stairs = i
			break
	for i in range(min(len(s), first_stairs + 1)):
		if bs[i] == '1':
			last_stairs = i
			break
	if min(first_stairs, last_stairs) > n:
		print(n)
	else:
		print((len(s) - min(first_stairs, last_stairs)) * 2)


def Starirs(s, n):
	c1 = s.find('1')
	if c1 == -1:
		return n
	c2 = s[::-1].index('1')
	maxm = max(2 * (n - c1), 2 * (n - c2))
	return maxm
t = int(input())
for _ in range(t):
	n = int(input())
	s = input().strip()
	ans = Starirs(s, n)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	first = -1
	last = -1
	for j in range(n):
		if s[j] == '1' and first == -1:
			first = j
		elif s[j] == '1':
			last = j
	if first == -1:
		print(n)
	elif last == -1:
		print(max((first + 1) * 2, (n - first) * 2))
	else:
		print(max((last + 1) * 2, (n - first) * 2))


for i in range(int(input())):
	n = int(input())
	s = str(input())
	a = s.find('1')
	s = s[::-1]
	b = s.find('1')
	if a == -1:
		print(len(s))
	else:
		print(2 * max(len(s) - a, len(s) - b))


for t in range(int(input())):
	n = int(input())
	str1 = input()
	mini = n - 1
	maxi = 0
	bol = True
	for i in range(n):
		if str1[i] == '1':
			bol = False
		if str1[i] == '1' and i > maxi:
			maxi = i
		if str1[i] == '1' and i < mini:
			mini = i
	if bol == True:
		print(n)
	mini = mini + 1
	maxi = maxi + 1
	diffmin = n - mini + 1
	diffmax = maxi
	if diffmax >= diffmin and bol == False:
		print(2 * diffmax)
	elif diffmax < diffmin and bol == False:
		print(2 * diffmin)


import math
n = int(input())
aux1 = 0
while aux1 < n:
	quartos = int(input())
	escada = input()
	achei = 0
	for i in range(0, math.ceil(quartos / 2)):
		if escada[i] == '1' or escada[quartos - (1 + i)] == '1':
			print((quartos - i) * 2)
			achei = 1
			break
	if achei == 0:
		print(quartos)
	aux1 += 1


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	if '1' in s:
		f = s.index('1')
		l = s[-1::-1].index('1')
		print(2 * (n - min(f, l)))
	else:
		print(n)


for t in range(int(input())):
	n = int(input())
	a = list(input())
	L = []
	L.append(n)
	(cnt, cnt1) = (0, 0)
	for i in a:
		if i == '0':
			cnt += 1
		if i == '1':
			L.append(2 * cnt1 + 2)
			cnt += 2
		cnt1 += 1
	L.append(cnt)
	(cnt, cnt1) = (0, 0)
	for i in range(n - 1, -1, -1):
		if a[i] == '0':
			cnt += 1
		if a[i] == '1':
			L.append(2 * cnt1 + 2)
			cnt += 2
		cnt1 += 1
	L.append(cnt)
	print(max(L))


t = int(input())
for tt in range(t):
	n = int(input())
	s = input().strip()
	r = -1
	l = -1
	for i in range(len(s)):
		if s[i] == '1':
			if l == -1:
				l = i
			r = i
	if l == -1:
		print(n)
	else:
		print(max(2 * (r + 1), 2 * (n - l)))


t = int(input())
for i in range(t):
	n = int(input())
	ans = n
	st = list(map(int, list(input())))
	for j in range(n):
		if st[j]:
			ans = max(ans, max(2 * j + 2, 2 * (n - j)))
	print(ans)


for itr in range(int(input())):
	n = int(input())
	l = list(input())
	if l.count('1') == 0:
		print(n)
		continue
	a = l.index('1')
	b = l[::-1].index('1')
	print(2 * max(n - a, n - b))


import re
no_of_lines = int(input())
input_lines = []
for i in range(2 * no_of_lines):
	input_lines.append(input())
flag = False
count = 0
for line in input_lines:
	if flag is False:
		stories = int(line)
		flag = True
	else:
		stairs = [m.start() for m in re.finditer('1', line)]
		if stairs:
			if stairs[0] == 0 or stairs[-1] == stories - 1:
				print(2 * stories)
			else:
				c1 = stairs[0]
				c2 = stairs[-1]
				c1_max = 2 * max(stories - c1, c1 + 1)
				c2_max = 2 * max(stories - c2, c2 + 1)
				print(max(c1_max, c2_max, stories + len(stairs)))
		else:
			print(stories)
		flag = False


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		f = input()
		if '1' not in f:
			print('{}'.format(n))
			continue
		posa = f.find('1')
		posb = f[::-1].find('1')
		minn = min(posa, posb)
		print('{}'.format(2 * n - 2 * minn))
main()


def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
import math
t = ii()
for i in range(t):
	n = ii()
	s = si()
	l = 0
	r = 0
	for i in range(0, n):
		if s[i:i + 1] == '1':
			l = i + 1
	for i in range(n - 1, -1, -1):
		if s[i:i + 1] == '1':
			r = n - i
	print(max(2 * l, 2 * r, n))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	try:
		(start, *_, end) = s.split('1')
		c = min(len(start), len(end))
		print(2 * (n - c))
	except ValueError:
		print(n)


import math
for i in range(int(input())):
	n = int(input())
	s = input()
	q = n
	p = n
	for i in range(n):
		if s[i] == '1':
			q = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			p = n - i - 1
			break
	if q == n and p == n:
		print(n)
	elif q > p:
		print(2 * (n - p))
	else:
		print(2 * (n - q))


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = n
	for i in range(n):
		if s[i] == '1':
			poo = 2 * max(n - i, i + 1)
			ans = max(ans, poo)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	a = s.find('1')
	if a == -1:
		print(n)
	elif a == 0:
		print(n * 2)
	elif a == n - 1:
		print(n * 2)
	else:
		b = s.rfind('1')
		z = n - b - 1
		if a < z:
			val = (n - a) * 2
		else:
			val = (b + 1) * 2
		print(val)


t = int(input())
for _ in range(t):
	n = int(input())
	r = input()
	if r.count('1') == 0:
		print(n)
	else:
		i = 0
		while i <= n // 2:
			if r[i] == '1' or r[-(i + 1)] == '1':
				print(2 * n - i * 2)
				break
			else:
				i += 1


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
from random import randint
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
test = int_input()
for _ in range(test):
	n = int_input()
	pattern = string_input()
	flag = 0
	middleIndex = len(pattern) // 2
	startingIndex = pattern.find('1')
	endingIndex = pattern.rfind('1')
	if startingIndex == -1 or endingIndex == -1:
		flag = 1
	if pattern[0] == '1' or pattern[-1] == '1':
		print(n * 2)
	elif startingIndex <= middleIndex and startingIndex + 1 <= len(pattern) - 1 - endingIndex and (flag == 0):
		print((n - startingIndex) * 2)
	elif endingIndex >= middleIndex and len(pattern) - 1 - endingIndex <= startingIndex + 1 and (flag == 0):
		print((endingIndex + 1) * 2)
	elif startingIndex + 1 == middleIndex and endingIndex + 1 == middleIndex:
		print(n + 1)
	elif flag == 1:
		print(n)


for _ in range(int(input())):
	x = int(input())
	s = input()
	if '1' in s:
		p = x - s.index('1')
		q = x - s[::-1].index('1')
		print(max(p, q) * 2)
	else:
		print(x)


t = int(input())
for t_ in range(t):
	n = int(input())
	s = input()
	from_start = n - s[::-1].find('1')
	from_end = n - s.find('1')
	max_rect = 0 if from_start > n or from_end > n else max(from_start, from_end) * 2
	print(max(max_rect, n + s.count('1')))


t = int(input())
for tc in range(t):
	n = int(input())
	rooms = input()
	fx = -1
	lx = -1
	for i in range(len(rooms)):
		if rooms[i] == '1':
			if fx == -1:
				fx = i
			lx = i
	if lx == -1:
		print(n)
	else:
		print(max((n - fx) * 2, (lx + 1) * 2))


for _ in range(int(input())):
	n = int(input())
	s = input().strip()
	if '1' in s:
		index1 = n - s.index('1')
		index2 = n - s[::-1].index('1')
		print(max(index1, index2) * 2)
	else:
		print(n)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	m = n
	for j in range(n):
		if s[j] == '1' or s[n - 1 - j] == '1':
			m = (n - j) * 2
			break
	print(m)


from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 7)

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))

def main():
	for _ in range(iin()):
		n = iin()
		a = input()
		occ = []
		ch = 0
		for i in a:
			ch += 1
			if i == '1':
				occ.append(ch)
		ans = n
		if occ:
			(mx, mn) = (occ[-1], occ[0])
			ans = max(ans, max(n - mx + 1, mx) * 2, max(n - mn + 1, mn) * 2)
		print(ans)
try:
	main()
except Exception as e:
	print(e)


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	s = input()
	s1 = s[::-1]
	s_one = n - s.find('1')
	s1_one = n - s1.find('1')
	if s.find('1') != -1:
		print(max(s1_one, s_one) * 2)
	else:
		print(n)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = str(input())
	arr2 = arr[::-1]
	count = 0
	if arr[0] == '1' or arr[n - 1] == '1':
		count = 2 * n
	elif '1' in arr:
		a = arr.index('1')
		b = arr2.index('1')
		if a > b:
			count = 2 * (n - b)
		else:
			count = 2 * (n - a)
	else:
		count = n
	print(count)


t = int(input())
while t:
	n = int(input())
	s = input()
	max_len = 0
	for (i, e) in enumerate(s):
		if e == '1':
			max_len = max(max_len, n - i, i + 1)
	print(max(2 * max_len, n))
	t -= 1


import math

def verifica1():
	quartos = int(input())
	metade = math.ceil(quartos / 2)
	escadas = input()
	for i in range(metade):
		if int(escadas[i]) == 1 or int(escadas[-(i + 1)]) == 1:
			return 2 * (quartos - i)
	return quartos
vezes = int(input())
for __ in range(vezes):
	print(verifica1())


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if '1' not in s:
		print(n)
		continue
	(first, last) = (s.find('1') + 1, s.rfind('1') + 1)
	print(max(2 * last, 2 * (n - first + 1)))


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input()))
	ans = n
	if 1 not in s:
		print(ans)
		continue
	for i in range(n):
		if s[i] == 1:
			ans = max(ans, n * 2 - i * 2)
			break
	for i in range(n - 1, -1, -1):
		if s[i] == 1:
			ans = max(ans, n * 2 - (n - 1 - i) * 2)
			break
	print(ans)


for _ in range(int(input())):
	n = int(input())
	mask = input()
	ans = n
	for (i, c) in enumerate(mask, 1):
		if c == '1':
			ans = max(ans, i * 2, (n - i + 1) * 2)
	print(ans)


n = int(input())
for i in range(n):
	a = -1
	b = -1
	l = int(input())
	s = input()
	for j in range(0, l, 1):
		if s[j] == '1':
			a = j + 1
			break
	for j in range(l - 1, -1, -1):
		if s[j] == '1':
			b = l - j
			break
	if a == -1 and b == -1:
		print(l)
	elif a >= b:
		print(2 * (l - b + 1))
	elif a < b:
		print(2 * (l - a + 1))


from math import ceil
ct = int(input())
for c in range(ct):
	n = int(input())
	s = input()
	ma = n
	for i in range(n):
		if s[i] == '1':
			ma = max(ma, (i + 1) * 2)
			ma = max(ma, (n - i) * 2)
	print(ma)


n = int(input())
for i in range(n):
	m = int(input())
	s = str(input())
	l = []
	if '0' not in s:
		print(len(s) * 2)
	elif '1' not in s:
		print(len(s))
	else:
		print(2 * max(m - s.index('1'), m - s[::-1].index('1')))


def f(k, y, x):
	return k + y + 2 * x

def way(s, check):
	(k, y, x, max_f) = (0, 0, n, n)
	while x > 0 and s[x - 1] == '0':
		x -= 1
	while x > 0:
		max_f = max(max_f, f(k, y, x))
		while x - y > 0 and s[y] == '0':
			y += 1
		k += 1
		y += 1
		x -= y
	max_f = max(max_f, n + k)
	if check:
		return max(max_f, way(s[::-1], 0))
	return max_f
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	print(way(s, 1))


R = lambda : int(input())
for i in [0] * R():
	b = R()
	s = input()
	n = s.find('1')
	print([2 * max(b - n, s.rfind('1') + 1), b][n < 0])


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	S = input()
	ans = N
	idx = S.rfind('1')
	if idx != -1:
		ans = max(ans, (idx + 1) * 2)
	idx = S.find('1')
	if idx != -1:
		ans = max(ans, (N - idx) * 2)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = [*input()]
	if l == ['0'] * n:
		print(n)
	else:
		k = l.copy()
		k.reverse()
		a = l.index('1')
		b = k.index('1')
		print(max(n - a, n - b) * 2)


t = int(input())
for i in range(t):
	(n, s) = (int(input()), input())
	(ix1, ix2) = (s.find('1'), s[::-1].find('1'))
	if ix1 == ix2 == -1:
		print(n)
		continue
	print(max(n - ix1, n - ix2) * 2)


import sys
n = int(input())
for _ in range(n):
	a = int(input())
	st = input()
	pos = 0
	k = 0
	for i in range(len(st)):
		if st[i] == '1':
			pos = i + 1
	for i in range(len(st) - 1, -1, -1):
		k += 1
		if st[i] == '1':
			pos1 = k
	if pos == 0:
		print(a)
	elif pos > pos1:
		print(2 * pos)
	else:
		print(2 * pos1)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	b = list()
	maxim = 0
	for i in range(n):
		if s[i] == '1':
			if maxim < max(i + 1, n - i):
				maxim = max(i + 1, n - i)
	print(max(maxim * 2, n))


t = int(input())
for te in range(t):
	n = int(input())
	a = input()
	ans = n
	for i in range(n):
		if a[i] == '1':
			ans = max(ans, 2 * max(i + 1, n - i))
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	pos = 0
	for i in range(0, n):
		if s[i] == '1' or s[n - 1 - i] == '1':
			pos = n - i
			break
	if pos == 0:
		print(n)
	else:
		print(2 * pos)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	if s.count('1') == 0:
		print(n)
	else:
		x = s.index('1')
		y = s.rindex('1')
		print(max(2 * (x + 1), 2 * (n - x), 2 * (y + 1), 2 * (n - y)))


from sys import stdin
from math import ceil
I = lambda : map(int, input().split())
Input = stdin.readline
for i in range(int(input())):
	n = int(input())
	a = input()
	try:
		print(max(len(a), (n - list(reversed(a)).index('1')) * 2, (n - a.index('1')) * 2))
	except:
		print(len(a))


from math import gcd, ceil
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
inp = lambda : int(stdin.readline())
sip = lambda : stdin.readline()
mulip = lambda : map(str, stdin.readline().split())
lst = lambda : list(map(int, stdin.readline().split()))
slst = lambda : list(sip())
M = pow(10, 9) + 7
for _ in range(inp()):
	n = inp()
	s = list(input())
	if s[0] == '1' or s[n - 1] == '1':
		print(2 * n)
	else:
		(maxx, tmp) = (0, 0)
		for i in range(n):
			if s[i] == '1':
				maxx = max(maxx, 2 * (i + 1))
				maxx = max(maxx, 2 * (n - i))
				tmp += 1
		maxx = max(maxx, tmp + n)
		print(maxx)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = []
	for j in range(n):
		if a[j] == '1':
			b.append(j)
	if len(b) == 0:
		print(n)
		continue
	c = b[0]
	d = b[-1]
	print(max((n - c) * 2, (d + 1) * 2))


for _ in range(int(input())):
	n = int(input())
	a = list(input())
	first = -1
	last = -1
	for i in range(n):
		if a[i] == '1':
			first = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == '1':
			last = i
			break
	if first != -1:
		a = 2 * (last + 1)
	else:
		a = 0
	if last != -1:
		b = 2 * (n - first)
	else:
		b = 0
	ans = max(a, b, n)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = list(input())
	ans = n
	for i in range(n):
		if s[i] == '1':
			if i >= n // 2:
				ans = max(ans, 2 * (i + 1))
			else:
				ans = max(ans, (n - i) * 2)
	print(ans)


b = int(input())
import math
for o in range(int(b)):
	q = input()
	c = input()
	z = c[::-1]
	v = ''
	for i in range(len(c)):
		if c[i] == '1' or z[i] == '1':
			v += '1'
		else:
			v += '0'
	a = v.find('1')
	if a == -1:
		print(len(z))
	else:
		c = len(z[:a])
		d = len(z[a:])
		print(2 * max(c, d))


from collections import defaultdict as dc
from collections import deque as dq
from bisect import bisect_left, bisect_right, insort_left
import sys
import math
mod = 10 ** 9 + 7

def bs(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def inp():
	p = sys.stdin.readline()
	return p

def line():
	p = list(map(int, inp().split()))
	return p
for _ in range(int(inp())):
	n = int(inp())
	s = str(input())
	if s[0] == '1' or s[n - 1] == '1':
		print(2 * n)
	else:
		ans = n
		c = s.count('1')
		if c == 0:
			print(ans)
		else:
			p = n - s.find('1')
			q = n - s[::-1].find('1')
			ans = ans + c
			print(max(ans, 2 * p, 2 * q))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	c = 0
	c1 = 0
	c2 = 0
	p = s[::-1]
	if s.count('1') == 0:
		c = n
	else:
		c1 = s.index('1')
		c2 = p.index('1')
		a = min(c1, c2)
		a = n - a
		c = 2 * a
	print(c)


def solve(string):
	nums = []
	for x in range(len(string)):
		if string[x] == '1':
			nums.append(x)
	if nums == []:
		return len(string)
	dist1 = 2 * (len(string) - nums[0])
	dist2 = 2 * (nums[-1] + 1)
	return max(dist1, dist2)
t = int(input())
for case in range(t):
	n = int(input())
	string = input()
	print(solve(string))


def solve(x):
	res = 0
	for i in range(n):
		if x[i] == '1':
			res = max(2 * (i + 1), i + 1 + n - i)
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	print(max(n, solve(s), solve(s[::-1])))


n = input()
n = int(n)
for i in range(0, n):
	k = input()
	l = input()
	rsta = []
	for j in range(0, int(k)):
		rsta.append(int(l[j]))
	stair = False
	for j in rsta:
		if j == 1:
			stair = True
	if stair == False:
		print(k)
	else:
		conmin = 10000
		conmax = -1
		con = 0
		for j in rsta:
			if j == 1:
				if con < conmin:
					conmin = con
				if con > conmax:
					conmax = con
			con = con + 1
		m1 = int(k) - conmin
		m2 = conmax + 1
		if m1 > m2:
			print(int(2 * m1))
		else:
			print(int(2 * m2))


t = int(input())
tests = list()
for _ in range(t):
	n = int(input())
	tests.append(input())
result = list()
for test in tests:
	try:
		left = test.index('1')
		right = test[::-1].index('1')
	except ValueError:
		result.append(len(test))
		continue
	start = min(left, right)
	result.append((len(test) - start) * 2)
for value in result:
	print(value)


for _ in range(int(input())):
	n = int(input())
	stairs = list(map(int, input()))
	max_rooms = 0
	if 1 in stairs:
		for i in range(n):
			if stairs[i]:
				max_rooms = max(2 * (i + 1), 2 * (n - i), max_rooms)
	else:
		max_rooms = n
	print(max_rooms)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in list(input())]
	index2 = index1 = n / 2
	for i in range(n):
		if a[i] == 1:
			index1 = max(i + 1, n - i)
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			index2 = max(i + 1, n - i)
			break
	print(int(max((2 * index2, 2 * index1))))


t = int(input())
for i in range(t):
	n = int(input())
	b = input()
	a = []
	for j in range(n):
		if b[j] == '1':
			a.append(j)
	if a == []:
		print(n)
	else:
		q = max(n - 1 - a[0], a[-1])
		print(2 * (q + 1))


from sys import stdin

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	n = iinput()
	s = input()
	if all((e == 0 for e in s)):
		print(n)
	else:
		ans = n
		for i in range(n):
			if s[i] == '1':
				ans = max(ans, 2 * (i + 1), 2 * (n - i))
		print(ans)


import sys
import itertools
import math
import collections
from collections import Counter

def pow(x, y, mod):
	r = 1
	x = x % mod
	while y > 0:
		if y & 1:
			r = r * x % mod
		y = y >> 1
		x = x * x % mod
	return r

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)
t = ii()
for _ in range(t):
	n = ii()
	s = input()
	if '1' not in s:
		print(n)
		continue
	l = r = -1
	f = True
	for i in range(n):
		if s[i] == '1':
			r = i
			if f:
				l = i
				f = False
	print(max(2 * (n - l), 2 * (r + 1)))


N = int(input())
for _ in range(N):
	room_cnt = int(input())
	floor_map = input()
	l = floor_map.find('1')
	if l == -1:
		print(room_cnt)
		continue
	r = floor_map.rfind('1')
	max_d = 2 * max(r + 1, room_cnt - l)
	print(max_d)


def solve(n, s):
	is_stairs = [s[x] == '1' for x in range(n)]
	if not any(is_stairs):
		return n
	if is_stairs[0] or is_stairs[-1]:
		return n * 2
	else:
		min_idx = max_idx = None
		for i in range(n):
			if not is_stairs[i]:
				continue
			if not min_idx:
				min_idx = i
			max_idx = i
		return max(max_idx + 1, n - min_idx) * 2
for _ in range(int(input())):
	n = int(input())
	s = input()
	r = solve(n, s)
	print(r)


for _ in range(int(input())):
	n = int(input())
	s = input()
	c = 0
	b = -1
	f = 10000
	for i in range(n):
		if s[i] == '1':
			c += 2
		else:
			c += 1
	for i in range(n):
		if s[i] == '1':
			f = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			b = i
			break
	k1 = (n - f) * 2
	k2 = (b + 1) * 2
	print(max(k1, k2, c))


T = int(input())
for _ in range(T):
	N = int(input())
	stairs = input()
	if not '1' in stairs:
		print(N)
	else:
		l1 = stairs.find('1')
		l2 = stairs[::-1].find('1')
		ans1 = 2 * max(N - l1, N - l2)
		ans2 = N + stairs.count('1')
		print(max(ans1, ans2))


def solve(n, string):
	blkg = 0
	dpn = n
	for i in range(n):
		s = string[i]
		t = string[-(i + 1)]
		if s == '1':
			dpn = i + 1
		if t == '1':
			blkg = i + 1
	if blkg == 0:
		return n
	else:
		return max(dpn, blkg) * 2
t = int(input())
for i in range(t):
	n = int(input())
	print(solve(n, input()))


def read():
	return list(map(int, input().split()))

def run():
	[n] = read()
	s = input()
	left = s.find('1')
	right = s[::-1].find('1')
	if left == -1:
		return n
	return 2 * n - 2 * min(left, right)
[t] = read()
for i in range(t):
	print(run())


t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	s = input().strip()
	ans = 0
	if s.count('1') == 1:
		zl = 0
		for i in range(n):
			zl += 1
			if s[i] == '1':
				break
		zr = 0
		for i in reversed(range(n)):
			zr += 1
			if s[i] == '1':
				break
		if zl > zr:
			ans = 2 * zl
		else:
			ans = 2 * zr
	if s.count('1') >= 2:
		zl = 0
		for i in range(n):
			zl += 1
			if s[i] == '1':
				break
		zr = 0
		for i in reversed(range(n)):
			zr += 1
			if s[i] == '1':
				break
		d1 = 0
		if zr > 0 and zl > 0:
			d1 = n - (zr + zl)
		if d1 >= zr:
			ans = zl + 2 * d1 + 3
		if d1 >= zl:
			if ans < zr + 2 * d1 + 3:
				ans = zr + 2 * d1 + 3
		if zl > d1 + zr:
			ans = 2 * zl
		if zl <= d1 + zr:
			ans = 2 * (d1 + zr) + 2
		if zr > d1 + zl:
			if ans < 2 * zr:
				ans = 2 * zr
		if zr <= d1 + zl:
			if ans < 2 * (d1 + zl) + 2:
				ans = 2 * (d1 + zl) + 2
	if '1' not in s:
		print(n)
	elif s[0] == '1' or s[-1] == '1':
		print(2 * n)
	else:
		print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	fi = 1000000
	la = -1
	for j in range(n):
		if a[j] == '1':
			if j < fi:
				fi = j
			if j > la:
				la = j
	if la == -1:
		print(n)
		continue
	b = max(la + 1, n - fi)
	print(b * 2)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		S = input().strip()
		if S[0] == '1' or S[-1] == '1':
			print(n * 2)
		else:
			x = n + S.count('1')
			y = 0
			for (i, s) in enumerate(S):
				if s == '1':
					ma = max(n - i, i + 1)
					y = max(y, ma)
			print(max(x, y * 2))
main()


def test():
	n = input()
	s = input()
	left = right = -1
	for i in range(len(s)):
		if s[i] == '1':
			right = i
			if left == -1:
				left = i
	if left == -1:
		print(n)
		return
	left = len(s) - left
	right += 1
	mx = max(left, right)
	print(mx * 2)
t = int(input())
while t != 0:
	t -= 1
	test()


a = int(input())
for _ in range(a):
	x = int(input())
	li = list(map(int, input()))
	if 1 in li:
		a = li.index(1)
		li.reverse()
		b = li.index(1)
		print(2 * (x - min(a, b)))
	else:
		print(x)


def solve(n, s):
	ans = n
	last = -1
	for i in range(n):
		if s[i] == '1':
			ans = max(ans, i * 2 + 2)
			last = i
	(x, y) = (1, 0)
	if s[0] == '1':
		y = 2
		ans = 2 * n
	if last > 0:
		ans = max(max(x, y) + last * 2, ans)
	for i in range(2, n):
		if s[i] == '1':
			(x, y) = (max(y + 2, x + 1), max(x + 2, y + 1))
		else:
			(x, y) = (x + 1, y + 1)
		if i < last:
			ans = max(max(x, y) + (last - i) * 2, ans)
	return max(ans, x, y)
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ans = solve(n, s)
	s = s[::-1]
	ans = max(ans, solve(n, s))
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if '1' not in s:
		print(n)
	else:
		ans = 0
		for (i, ch) in enumerate(s):
			if ch == '1':
				ans = max(ans, 2 * (n - min(i, n - 1 - i)))
		print(ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def test():
	n = int(input())
	s = input()
	q = n
	w = n
	for i in range(n):
		if s[i] == '1':
			q = i
			break
	s = s[::-1]
	for i in range(n):
		if s[i] == '1':
			w = i
			break
	m = min(q, w)
	print(max(n, 2 * (n - m)))
t = int(input())
while t:
	test()
	t -= 1


import sys
ip = lambda : sys.stdin.readline().rstrip()
for _ in range(int(ip())):
	n = int(ip())
	s = ip()
	if '1' not in s:
		print(n)
		continue
	ans = n
	for i in range(n):
		if s[i] == '1':
			ans = max(ans, 2 * (i + 1))
			ans = max(ans, 2 * (n - i))
	print(ans)


for _ in range(int(input())):
	n = int(input())
	st = list(input())
	(left, right) = (n, -1)
	for i in range(n):
		if st[i] == '1':
			left = i
			break
	for i in range(n - 1, -1, -1):
		if st[i] == '1':
			right = i
			break
	d = max(n, 2 * (n - left), 2 * (right + 1))
	print(d)


def rooms():
	n = int(input())
	staircases = input()
	counter = 1
	staircases_indexes = []
	for i in staircases:
		if i == '1':
			if counter <= int(n / 2):
				staircases_indexes.append(n - counter + 1)
			else:
				staircases_indexes.append(counter)
		counter += 1
	if staircases_indexes == []:
		print(n)
	else:
		staircase_to_be_considered = max(staircases_indexes)
		print(2 * staircase_to_be_considered)
test_cases = int(input())
while test_cases:
	rooms()
	test_cases -= 1


for _ in range(int(input())):
	l = int(input())
	s = input()
	first = -1
	end = -1
	i = 0
	while i < l:
		if s[i] == '1':
			if first == -1 and end == -1:
				first = i
				end = i
			else:
				end = i
		i += 1
	if first == -1:
		print(l)
	else:
		print(2 * max(l - first, end + 1))


for i in range(int(input())):
	n = int(input())
	s = input()
	if '1' in s:
		first = n - s.index('1')
		last = s.rindex('1') + 1
		print(max(first * 2, last * 2))
	else:
		print(len(s))


import math
import itertools

class Home:

	def __init__(self, n, s):
		self.n = n
		self.s = s

	def result(self):
		if ''.join(set(s)) == '0':
			return n
		elif ''.join(set(s)) == '1':
			return n * 2
		else:
			t = s.index('1')
			t1 = s[::-1].index('1')
			if t <= t1:
				return (n - t) * 2
			else:
				return (n - t1) * 2
t = int(input())
result = list(range(t))
for i in range(t):
	n = int(input())
	s = input()
	q = Home(n, s)
	result[i] = q.result()
for i in range(t):
	print(result[i])


t = int(input())
for x in range(t):
	n = int(input())
	s1 = list(input())
	if '1' in s1:
		s2 = s1.copy()
		s2.reverse()
		c1 = s2.index('1')
		c2 = s1.index('1')
		print(max(n - c1, n - c2) * 2)
	else:
		print(n)


for i in range(int(input())):
	n = int(input())
	k = input()
	if '1' in k:
		h = k.index('1')
		k = k.rindex('1') + 1
		print(2 * (n - min(h, n - 1 - h, n - k, k)))
	else:
		print(n)


for i in range(int(input())):
	n = int(input())
	s = input()
	one = 0
	(first, last) = (0, 0)
	for el in range(len(s)):
		if s[el] == '1':
			if one == 0:
				first = el
			one += 1
			last = el
	if one < 1:
		print(n)
	elif s[0] == s[-1] == '0':
		print(max(2 * (last + 1), 2 * (n - first)))
	else:
		print(2 * n)


import collections
for t in range(int(input())):
	n = int(input())
	s = input()
	(f, l) = (s.find('1'), s.rfind('1'))
	(f, l) = (max(f + 1, n - f) if f != -1 else 0, max(l + 1, n - l) if l != -1 else 0)
	if not f and (not l):
		print(n)
	else:
		print(f * 2) if f > l else print(l * 2)


for _ in range(int(input())):
	n = int(input())
	l = input()
	if '1' in l:
		le = l.index('1')
		ri = l[::-1].index('1')
		print((n - min(le, ri)) * 2)
	else:
		print(n)


t = int(input())
for qwe in range(t):
	n = int(input())
	s = input()
	a = [i + 1 for i in range(len(s)) if s[i] == '1']
	if a == []:
		print(n)
		continue
	mx = a[-1]
	mn = a[0]
	ans = max(mx, n - mn + 1) * 2
	print(ans)


for _ in range(int(input())):
	mega = []
	n = int(input())
	s = input()
	ans = n
	for i in range(n):
		if s[i] == '1':
			curr = 2 * max(n - i, i + 1)
			ans = max(ans, curr)
	print(ans)


import math
t = int(input())
for i in range(t):
	n = int(input())
	num = input()
	array = list(map(int, str(num)))
	min_s = n
	max_s = 0
	for i in range(n):
		if array[i] == 1:
			min_s = i
			break
	for i in range(n - 1, 0, -1):
		if array[i] == 1:
			max_s = i
			break
	if min_s == n and max_s == 0:
		print(n)
	elif n - (max_s + 1) < min_s:
		print((max_s + 1) * 2)
	else:
		print((n - min_s) * 2)


q = int(input())
for i in range(q):
	n = int(input())
	a = list(input())
	if (a[0] or a[n - 1]) == 1:
		print(2 * n)
	elif max(a) == '0':
		print(n)
	else:
		b = []
		b.append(a.index('1'))
		a.reverse()
		b.append(a.index('1'))
		print(2 * (n - min(b)))


for _ in range(int(input())):
	n = int(input())
	x = input()
	maxv = n
	for i in range(n):
		if x[i] == '1':
			maxv = max([maxv, 2 * i + 2, 2 * (n - i)])
	print(maxv)


n = int(input())
for i in range(n):
	r = int(input())
	a = input()
	ans = r
	for j in range(r):
		if a[j] == '1':
			x = max(2 * (r - j), 2 * (j + 1))
			if x > ans:
				ans = x
	print(ans)


from sys import stdin

def scal(typ=int):
	return typ(stdin.readline())

def vec(typ=int):
	if isinstance(typ, list):
		inp = stdin.readline().split()
		return [typ[i](inp[i]) for i in range(len(inp))]
	else:
		return list(map(typ, stdin.readline().split()))
t = scal()
for _ in range(t):
	n = scal()
	s = scal(str)
	(f, l) = (s.find('1'), s.rfind('1') + 1)
	print(n) if f == -1 else print(2 * max(l, n - f))


def cal(s):
	n = len(s)
	for i in range(1, n + 1):
		if s[-i] == '1':
			return (n - i + 1) * 2
	return n
q = int(input())
for run in range(q):
	n = int(input())
	s = input()
	print(max(cal(s), cal(s[::-1])))


for nt in range(int(input())):
	n = int(input())
	s = input()
	if '1' not in s:
		print(n)
		continue
	ans = n
	for i in range(n):
		if s[i] == '1':
			ans = max(ans, (i + 1) * 2, (n - i) * 2)
	print(ans)


t = int(input())
s = []
for nfk in range(0, t):
	n = int(input())
	x = input()
	m1 = 0
	m2 = 0
	for i in range(0, n):
		if x[i] == '1':
			m1 = n - i
			break
	for i in range(n - 1, -1, -1):
		if x[i] == '1':
			m2 = i + 1
			break
	if m1 != 0 or m2 != 0:
		p = [2 * m1, 2 * m2]
		s.append(max(p))
	else:
		s.append(n)
for i in s:
	print(i)


import sys
t = int(input())
while t > 0:
	n = int(input())
	s = input()
	result = len(s)
	for (i, v) in enumerate(s):
		if v != '1':
			continue
		result = max(result, (i + 1) * 2)
		result = max(result, (len(s) - i) * 2)
	print(result)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input()))[:n]
	if s.count(1) == 0:
		print(n)
	elif s.count(1) == n:
		print(n * 2)
	else:
		max1 = 0
		max2 = 0
		for j in range(0, n):
			if s[j] == 1:
				if max1 < j + 1:
					max1 = j + 1
		d = n - 1
		count = 0
		while d >= 0:
			count += 1
			if s[d] == 1:
				if max2 < count:
					max2 = count
			d -= 1
		p = max(max1, max2)
		print(p * 2)


for i in range(int(input())):
	n = int(input())
	v = input()
	c = 0
	d = 0
	for j in v:
		c += 1
		if j == '1':
			break
		else:
			pass
	for k in range(n):
		d += 1
		if v[-1 - k] == '1':
			break
		else:
			pass
	if n == 1:
		if v == '1':
			print(2)
		else:
			print(1)
	elif (c == n) & (d == n) & (n != 1):
		print(n)
	else:
		c = n - c + 1
		d = n - d + 1
		print(2 * max(c, d))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for j in range(int(input())):
	n = int(input())
	vals = [int(k) for k in input()]
	last = -1
	first = -1
	for s in range(n):
		if vals[s] == 1:
			last = s
			if first == -1:
				first = s
	if last == -1:
		print(n)
	else:
		a1 = last + 1
		a2 = max(last + 1, n - last)
		b1 = n - first
		b2 = max(first + 1, n - first)
		ans1 = a1 + a2
		ans2 = b1 + b2
		print(max(ans1, ans2))


n = int(input())
for i in range(n):
	number_of_rooms = int(input())
	rooms = list(input())
	if '1' not in rooms:
		answer = number_of_rooms
	else:
		for j in range(number_of_rooms):
			if rooms[j] == '1':
				answer1 = len(rooms[j:]) * 2
				break
		rooms = rooms[::-1]
		for k in range(number_of_rooms):
			if rooms[k] == '1':
				answer2 = len(rooms[k:]) * 2
				break
		if answer1 >= answer2:
			answer = answer1
		else:
			answer = answer2
	print(answer)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(first, last) = (0, 0)
	for i in range(n // 2 + 1):
		if s[i] == '1':
			first = n - i
			break
	for i in range(n - 1, n // 2 - 1, -1):
		if s[i] == '1':
			last = i + 1
			break
	case1 = max(last, first) * 2
	print(max(n, case1))


t = int(input())
s = []
a = []
for i in range(t):
	a.append(int(input()))
	s.append(input())
for j in range(t):
	n = a[j]
	st = s[j]
	if st.count('1') == 0:
		print(n)
	elif st[0] == '1' or st[-1] == '1':
		print(2 * n)
	else:
		b = []
		for g in range(n):
			if st[g] == '1':
				b.append(g)
		print(2 * n - 2 * min(b[0], n - (b[-1] + 1)))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if not '1' in s:
		print(n)
		continue
	first = s.index('1')
	poss1 = 2 * (n - first)
	last = s[::-1].index('1')
	poss2 = 2 * (n - last)
	print(max(poss1, poss2))


tests = int(input())
for test in range(0, tests):
	rooms = int(input())
	stairs = input()
	for i in range(len(stairs)):
		if stairs[i] == '1':
			leftIndex = i
			break
		leftIndex = -1
	if leftIndex != -1:
		for i in range(len(stairs) - 1, -1, -1):
			if stairs[i] == '1':
				rightIndex = i
				break
		if rightIndex == leftIndex:
			print(2 * max(rooms - leftIndex, leftIndex + 1))
		else:
			print(2 * (rooms - min(leftIndex, rooms - rightIndex - 1)))
	else:
		print(rooms)


import sys, os, io
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input().strip()
	try:
		x = s.index('1')
		x = n - x
		y = s[::-1].index('1')
		y = n - y
		print(2 * max(x, y))
	except:
		print(n)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if set(s) == {'0'}:
		print(len(s))
	else:
		ans = 0
		for i in range(n):
			if s[i] == '1':
				ans = max(ans, (i + 1) * 2, 2 * (n - i))
		print(ans)


t = int(input())

def how_many(n, a):
	k = a.count(1)
	if k == 0:
		return n
	left = n - 1
	right = 0
	for i in range(n):
		if a[i] == 1:
			left = i
			break
	for i in range(n - 1, 0, -1):
		if a[i] == 1:
			right = i
			break
	if right == n - 1 or left == 0:
		return 2 * n
	else:
		return max(right, n - left - 1) * 2 + 2
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip()))
	print(how_many(n, a))


import sys, math

def input():
	return sys.stdin.readline()[:-1]

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = input()
		ans1 = 0
		ans2 = 0
		for k in range(n):
			if s[k] == '1':
				ans1 = 2 * (k + 1)
		for k in range(n):
			if s[-k - 1] == '1':
				ans2 = 2 * (k + 1)
		print(max(n, ans1, ans2))
main()


for _ in range(int(input())):
	num_of_rooms = int(input())
	bit_map = input()
	last_ladder_position = 0
	first_ladder_position = 0
	if not '1' in bit_map:
		print(num_of_rooms)
		continue
	else:
		for i in range(num_of_rooms - 1, -1, -1):
			if bit_map[i] == '1':
				last_ladder_position = i
				break
		for i in range(0, num_of_rooms):
			if bit_map[i] == '1':
				first_ladder_position = i
				break
	ladder_position = max(num_of_rooms - 1 - first_ladder_position, last_ladder_position)
	if ladder_position < (num_of_rooms - 1) // 2:
		print(num_of_rooms + 1)
	else:
		print((ladder_position + 1) * 2)


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
t = rint()
for _ in range(t):
	n = rint()
	s = input()
	mx = n
	for i in range(n):
		if s[i] == '0':
			continue
		mx = max(mx, 2 * max(i + 1, n - i))
	print(mx)


t = int(input())
for w in range(t):
	n = int(input())
	s = list(input())
	if s[0] == '1' or s[-1] == '1':
		print(n * 2)
		continue
	indexOf1 = []
	bool = False
	for i in range(n):
		if s[i] == '1':
			indexOf1.append(i)
			bool = True
	if not bool:
		print(n)
		continue
	print(max((n - indexOf1[0]) * 2, (indexOf1[-1] + 1) * 2))


t = int(input())
for i in range(t):
	n = int(input())
	inp_str = input()
	flag = False
	for j in range(n):
		if inp_str[j] == '1':
			flag = True
			start = j
			break
	if flag == True:
		for j in range(n - 1, -1, -1):
			if inp_str[j] == '1':
				end = j
				break
		value = max(n - start, end + 1)
		print(2 * value)
	else:
		print(n)


t = int(input())
while t != 0:
	n = int(input())
	l = input()
	count = 0
	for i in range(n):
		if l[i] == '1' or l[n - i - 1] == '1':
			count += 1
			rooms = 2 * n - 2 * i
			print(rooms)
			break
	if count == 0:
		print(n)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = [int(x) for x in list(input())]
	left = 0
	right = n - 1
	van = False
	for i in range(n):
		if s[i] == 1:
			van = True
			left = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == 1:
			van = True
			right = i
			break
	if not van:
		print(n)
	elif left >= n - 1 - right:
		print((right + 1) * 2)
	else:
		print((n - left) * 2)


t = int(input())
for _ in range(t):
	n = int(input())
	ladL = list(input())
	k = len(ladL)
	if '1' in ladL:
		for i in range(k):
			if ladL[i] == '1':
				ind1 = i
				break
		for j in range(k):
			if ladL[j] == '1':
				ind2 = j
		ind = min(ind1, k - 1 - ind2)
		ret = 2 * (k - ind)
	else:
		ret = k
	print(ret)


for _ in range(int(input())):
	n = int(input())
	x = input()
	y = x[::-1]
	frv = 0
	rrv = 0
	f_in = 0
	if '1' in x:
		f_in = x.index('1')
		ffrv = (f_in + 1) * 2
		frrv = (n - f_in) * 2
		if ffrv >= frrv:
			frv = ffrv
		else:
			frv = frrv
		y = x[::-1]
		f_in = y.index('1')
		rfrv = (f_in + 1) * 2
		rrrv = (n - f_in) * 2
		if rfrv > rrrv:
			rrv = rfrv
		else:
			rrv = rrrv
	else:
		frv = n
	if frv > rrv:
		print(frv)
	else:
		print(rrv)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if s.count('1') == 0:
		print(n)
	else:
		c1 = n - s.find('1')
		c2 = s.rfind('1') + 1
		print(max(c1, c2) * 2)


for i in range(int(input())):
	n = int(input())
	s = input()
	f = s.find('1')
	s2 = s.rfind('1')
	if f == -1:
		print(n)
	elif f != -1 and s2 == -1:
		print(n + 1)
	elif f < n - s2 - 1:
		print(2 * (n - f))
	else:
		print(2 * (s2 + 1))


import math
for i in range(int(input())):
	n = int(input())
	s = str(input())
	if s[-1] == '1' or s[0] == '1':
		print(2 * len(s))
	elif s.count('1') > 0:
		a = s.index('1')
		b = n - 1 - s[::-1].index('1')
		print(max((n - a) * 2, (b + 1) * 2))
	else:
		print(n)


cases = int(input())
for _ in range(cases):
	n = int(input())
	c = list(input())
	flag = 0
	if c[0] == '1' or c[-1] == '1' or c.count('0') == 0:
		print(2 * n)
	elif c.count('1') == 0:
		print(n)
	else:
		for i in range(n):
			if c[i] == '1':
				break
		c = c[::-1]
		for j in range(n):
			if c[j] == '1':
				break
		l = min(i, j)
		print(2 * (n - l))


from math import ceil
n = int(input())
for _ in range(n):
	nr = int(input())
	rooms = input().rstrip()
	maxn = -1
	for (i, v) in enumerate(rooms):
		if v == '1':
			ls = i
			rs = nr - i - 1
			s = max(ls, rs)
			maxn = max(maxn, s)
	if maxn == -1:
		print(nr)
	else:
		print((maxn + 1) * 2)


mod = 10 ** 9 + 7
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
import collections
import math
import heapq
from random import randint as rn

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def main():
	t = inin()
	for _ in range(t):
		n = inin()
		s = sin()
		ss = 0
		for i in range(n):
			if s[i] == '1':
				m = max(i + 1, n - i)
				ss = max(ss, 2 * m)
		print(max(ss, n))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


t = int(input())
lst_output = []
for i in range(t):
	n = int(input())
	lst = list(map(int, input()))
	output = 0
	new_output = n
	if n % 2 == 0:
		last = n // 2
	else:
		last = n // 2 + 1
	for j in range(last):
		if j == 0 and lst[j] == 1:
			output = 2 * n
			break
		elif j == n // 2 and lst[j] == 1:
			new_output = (j + 1) * 2
		elif j == n // 2 - 1 and lst[j] == 1:
			if n % 2 == 0:
				new_output = (j + 1) * 2
			else:
				new_output = 2 * (n - j)
		elif lst[j] == 1:
			new_output = 2 * (n - j)
		if new_output > output:
			output = new_output
	if output != 2 * n:
		for j in range(n - 1, last - 1, -1):
			if j == len(lst) - 1 and lst[j] == 1:
				output = 2 * n
				break
			elif j == n // 2 and lst[j] == 1:
				if n % 2 == 0:
					new_output = (j + 1) * 2
			elif lst[j] == 1:
				new_output = 2 * (j + 1)
			if new_output > output:
				output = new_output
	lst_output.append(output)
for k in range(len(lst_output)):
	print(lst_output[k])


import array
import math
import os
import sys

def main():
	T = read_int()
	for _ in range(T):
		N = read_int()
		S = [int(c) for c in inp()]
		print(solve(N, S))

def solve(N, S):
	if S[0] or S[N - 1]:
		return 2 * N
	if S.count(1) == 0:
		return N
	i = S.index(1)
	S.reverse()
	j = S.index(1)
	return max((i + 1) * 2, (N - i) * 2, (j + 1) * 2, (N - j) * 2)
DEBUG = 'DEBUG' in os.environ

def inp():
	return sys.stdin.readline().rstrip()

def read_int():
	return int(inp())

def read_ints():
	return [int(e) for e in inp().split()]

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)
main()


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import *
(t,) = I()
while t:
	t -= 1
	(n,) = I()
	s = input()
	ans = n
	for i in range(n):
		if s[i] == '0':
			continue
		j = n - i
		ans = max(ans, 2 * (i + 1), 2 * j)
	print(ans)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def main():
	for _ in range(int(input())):
		n = int(input())
		S = input()
		s = []
		for i in S:
			if i == '1' or i == '0':
				s.append(i)
		minn = len(s)
		maxx = -1
		for i in range(len(s)):
			if s[i] == '1':
				minn = min(minn, i)
				maxx = max(maxx, i)
		print(max(n, 2 * (maxx + 1), 2 * (len(s) - minn)))
	return
main()


import math
from collections import deque, defaultdict
from sys import stdin, stdout
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
intin = lambda : int(input())
for _ in range(intin()):
	n = intin()
	s = input()
	f = -1
	l = -1
	for i in range(n):
		if s[i] == '1':
			if f == -1:
				f = i
			l = i
	if f == l == -1:
		print(n)
	else:
		f = n - f
		l = l + 1
		print(max(n, f * 2, l * 2))


t = int(input())
for i in range(t):
	a = int(input())
	b = input()
	maxs = 0
	if b[0] == '1' or b[-1] == '1':
		print(a * 2)
	else:
		for i in range(len(b)):
			if b[i] == '1':
				a1 = max(i + 1, a - i)
				if a1 > maxs:
					maxs = a1
		if maxs == 0:
			print(a)
		else:
			print(maxs * 2)


import sys
inputlist = sys.stdin.readlines()
number_of_testcases = int(inputlist[0])
i = 1
while i <= 2 * number_of_testcases:
	n = int(inputlist[i])
	i += 1
	firstoneindex = 0
	while firstoneindex < n and inputlist[i][firstoneindex] != '1':
		firstoneindex = firstoneindex + 1
	if firstoneindex == n:
		print(n)
		i += 1
		continue
	lastoneindex = n - 1
	while inputlist[i][lastoneindex] != '1':
		lastoneindex = lastoneindex - 1
	first_value = (lastoneindex + 1) * 2
	second_value = (n - firstoneindex) * 2
	to_print = first_value if first_value > second_value else second_value
	print(to_print)
	i += 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	ones = []
	for i in range(n):
		if s[i] == '1':
			ones.append(i)
	if len(ones) == 0:
		print(n)
	elif ones[0] < n - 1 - ones[-1]:
		print(2 * (n - ones[0]))
	else:
		print(2 * (ones[-1] + 1))


t = int(input())

def f(s):
	if s[0] == '1' or s[-1] == '1':
		return 2 * len(s)
	for i in range(0, len(s)):
		if s[i] == '1':
			a = i
			break
	if i == len(s) - 1:
		return len(s)
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			b = i
			break
	m = max(b + 1, len(s) - a)
	return 2 * m
for i in range(0, t):
	n = input()
	s = input()
	print(f(s))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	m = 0
	q = 0
	if s[n - 1] == '1' or s[0] == '1':
		print(n * 2)
	else:
		for i in range(n):
			if s[i] == '1':
				if m <= i + 1 - 0:
					m = i + 1
				if m <= n - i:
					m = n - i
			else:
				q += 1
		if q == n:
			print(n)
		else:
			print(2 * m)


for _ in range(int(input())):
	(n, s) = (int(input()), input())
	(maximum, count) = (n, 0)
	for j in range(n):
		if s[j] == '1':
			maximum = max(maximum, max(2 * (n - j), 2 * (j + 1)))
	print(max(maximum, count))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ma = n
	st = -1
	f = -1
	for j in range(n):
		if s[j] == '1':
			st = j
			break
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			f = j
			break
	if f != -1:
		ma = max(ma, (f + 1) * 2)
		ma = max(ma, (n - st) * 2)
	print(ma)


t = int(input())
for i in range(t):
	n = int(input())
	r = input()
	m = 0
	for j in range(n):
		if r[j] == '1':
			m = max(m, j + 1, n - j)
	result = max(n, 2 * m)
	print(result)


def max(a, b):
	if a > b:
		return a
	else:
		return b

def func(n, sc):
	counter = 0
	last = -1
	for j in range(len(sc)):
		if sc[j] == '1':
			counter = counter + 1
			if j > last:
				last = j
	if last == -1:
		return n
	else:
		return max(2 * (last + 1), n + counter)
t = int(input())
for i in range(t):
	n = int(input())
	sc = input()
	reverse = sc[len(sc)::-1]
	print(max(func(n, sc), func(n, reverse)))


import math
q = int(input())
while q > 0:
	n = int(input())
	s = input()
	L = []
	for i in range(len(s)):
		L.append(s[i])
	if '1' not in L:
		print(n)
	else:
		a1 = L.index('1')
		L.reverse()
		a2 = L.index('1')
		d = min(a1, a2)
		print((n - d) * 2)
	q -= 1


t = int(input())
for t_ in range(t):
	n = int(input())
	stairs = input().strip()
	cand_1 = 0
	cand_2 = 0
	for (i, val) in enumerate(stairs):
		if val == '1':
			cand_1 = max(i + 1, n - i)
			break
	for (i, val) in enumerate(reversed(stairs)):
		if val == '1':
			cand_2 = max(i + 1, n - i)
			break
	if cand_1:
		print(max(cand_1, cand_2) * 2)
	else:
		print(n)


for i in range(int(input())):
	N = int(input())
	X = input()
	(First, Last) = (0, 0)
	Rooms = 0
	if '1' in X:
		(First, Last) = (X.index('1'), X[::-1].index('1'))
		First = N - First
		Last = N - Last
		print(max(First, Last) * 2)
	else:
		print(N)


for _ in range(int(input())):
	no = int(input())
	room = input()
	count = 0
	if room[-1] == '0' and room[0] != '0':
		for i in range(len(room) - 1, -1, -1):
			if room[i] == '0':
				count += 1
			elif room[i] == '1' and '1' in room[:i]:
				count += 1
			else:
				count += 1
				count *= 2
				break
	elif room[-1] == '0' and room[0] == '0':
		new = room.split('1')
		if len(new[0]) > len(new[-1]):
			for i in range(0, len(room)):
				if room[i] == '0':
					count += 1
				elif room[i] == '1' and '1' in room[i + 1:]:
					count += 1
				else:
					count += 1
					count *= 2
					break
		else:
			for i in range(len(room) - 1, -1, -1):
				if room[i] == '0':
					count += 1
				elif room[i] == '1' and '1' in room[:i]:
					count += 1
				else:
					count += 1
					count *= 2
					break
	else:
		for i in range(0, len(room)):
			if room[i] == '0':
				count += 1
			elif room[i] == '1' and '1' in room[i + 1:]:
				count += 1
			else:
				count += 1
				count *= 2
				break
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	string = input()
	val = 0
	if '1' not in string:
		print(n)
	else:
		for i in range(len(string)):
			if string[i] == '1':
				temp = max((2 * (i + 1), 2 * (n - i)))
				if temp > val:
					val = temp
		print(val)


t = int(input())

def solve():
	n = int(input())
	s = input()
	if all(map(lambda x: x == '0', s)):
		return n
	if all(map(lambda x: x == '1', s)):
		return n * 2
	a = b = None
	for i in range(n):
		if s[i] == '1' and a is None:
			a = i
		if s[i] == '1':
			b = i
	return max((b + 1) * 2, (n - a) * 2)
for _ in range(t):
	print(solve())


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = list(map(int, input()))
	v = n
	for i in range(n):
		if s[i] == 1:
			v = max(v, 2 * (i + 1), 2 * (n - i))
	print(v)


t = int(input())
for i in range(t):
	n = int(input())
	floor = input()
	if '1' not in floor:
		print(n)
	elif '0' not in floor:
		print(2 * n)
	else:
		print(max([2 * (floor.rfind('1') + 1), 2 * (floor[::-1].rfind('1') + 1), n + 1]))


for _ in [0] * int(input()):
	n = int(input())
	a = input()
	if a.count('1') == 0:
		print(n)
	else:
		c = a.split('1')
		print(max((''.join(c[:-1]).count('0') + len(c[:-1])) * 2, (''.join(c[1:]).count('0') + len(c[1:])) * 2))


t = int(input())
for w in range(t):
	n = int(input())
	l = list(input())
	l1 = l[::-1]
	if l == ['0'] * n:
		print(n)
	else:
		print((max(n - l.index('1') - 1, n - l1.index('1') - 1) + 1) * 2)


t = int(input())
o = ''
for _ in range(t):
	n = int(input())
	s = [i for i in input()]
	if '1' not in s:
		o += f'{n}\n'
	else:
		index_1 = s.index('1')
		s.reverse()
		index_2 = s.index('1')
		o += f'{2 + max(2 * max(n - index_1 - 1, index_1), 2 * max(n - index_2 - 1, index_2))}\n'
print(o)


t = int(input())
for i in range(0, t):
	n = int(input())
	l = [int(j) for j in list(input())]
	if l[0] or l[-1]:
		print(n * 2)
		continue
	firstl = -1
	lastl = -1
	for j in range(0, len(l)):
		if firstl == -1 and l[j]:
			firstl = j
		if l[j]:
			lastl = j
	val1 = -1
	if firstl != -1:
		val1 = (n - min(firstl, len(l) - lastl - 1)) * 2
	s = 0
	for j in range(0, len(l)):
		if l[j] == 1:
			s += 2
		else:
			s += 1
	print(max(s, val1))


for _ in range(int(input())):
	n = int(input())
	arr = list(input())
	indr = 0
	indl = 0
	for i in range(n - 1, -1, -1):
		if arr[i] == '1':
			indr = i + 1
			break
	for i in range(n):
		if arr[i] == '1':
			indl = i + 1
			break
	if indr == 0:
		print(n)
	else:
		ind = max(indr, n - indl + 1)
		print(2 * ind)


t = int(input())
for i in range(t):
	n = int(input())
	listn = input()
	x = n
	numbers = [int(i) for i in listn]
	for j in range(n):
		if numbers[j] == 1:
			x = (n - j) * 2
			break
		if numbers[n - j - 1] == 1:
			x = (n - j) * 2
			break
	print(x)


for _ in range(int(input())):
	n = int(input())
	lad = input()
	if '1' not in lad:
		print(n)
		continue
	for i in range(n):
		if lad[i] == '1':
			first = i
			break
	for i in range(n - 1, -1, -1):
		if lad[i] == '1':
			last = i
			break
	print(max((last + 1) * 2, (n - first) * 2, n + lad.count('1')))


import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	if s.count('1') == 0:
		print(n)
	else:
		one = s.index('1')
		two = s[::-1].index('1')
		print(2 * max(one + 1, n - one, two + 1, n - two))


def solve(rooms):
	ans = len(rooms)
	for (i, ch) in enumerate(rooms):
		if ch == '1':
			ans = max(ans, 2 * (len(rooms) - i))
			break
	for (i, ch) in enumerate(reversed(rooms)):
		if ch == '1':
			ans = max(ans, 2 * (len(rooms) - i))
			break
	return ans
t = int(input())
for _ in range(t):
	input()
	print(solve(input()))


import math
t = int(input())
for _ in range(0, t):
	n = int(input())
	s = input()
	if s.count('1') == 0:
		print(len(s))
	else:
		c1 = s.rindex('1')
		s1 = s[::-1]
		c2 = s1.rindex('1')
		m = -1
		if c1 > c2:
			m = c1
		else:
			m = c2
		ans = m
		if n - 1 - m > m:
			ans = ans + n - 1 - m
		else:
			ans = ans + m + 1
		print(ans + 1)


def main():
	import sys
	input = sys.stdin.readline

	def solve():
		n = int(input())
		s = input()
		(l, r) = (-1, -1)
		for i in range(n):
			if s[i] == '1':
				if l == -1:
					l = i
				r = i
		if l == -1:
			print(n)
		else:
			print(2 * max(r + 1, n - l))
	for _ in range(int(input())):
		solve()
	return 0
main()


import os

def f(s):
	for i in range(len(s) // 2 + 1):
		if s[i] == '1':
			return (len(s) - i) * 2
		elif s[len(s) - i - 1] == '1':
			return (len(s) - i) * 2
	return len(s)
if os.environ.get('DEBUG', False):
	print(f"{f('00100')} = 6")
	print(f"{f('00000000')} = 8")
	print(f"{f('11111')} = 10")
	print(f"{f('110')} = 6")
	print(f"{f('1')} = 2")
	print(f"{f('0')} = 1")
	print(f"{f('0001')} = 8")
	print(f"{f('0010')} = 6")
else:
	t = int(input())
	for _ in range(t):
		input()
		print(f(input()))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	l = s.find('1')
	r = n - 1 - s.rfind('1')
	if l < 0:
		print(n)
	else:
		mn = min(l, r)
		print((n - mn) * 2)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def li():
	return [int(i) for i in input().rstrip('\n').split(' ')]

def val():
	return int(input().rstrip('\n'))

def st():
	return input().rstrip('\n')

def sttoli():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	n = val()
	l = sttoli()
	left = right = None
	for i in range(len(l)):
		if l[i] == 1 and left == None:
			left = i
		if l[i] == 1:
			right = i
	if sum(l) > 1:
		a = left + 2 * (right - left + 1)
		b = left + 1 + (right - left + 1) + (n - right)
		c = n - right - 1 + 2 * (right - left + 1)
		d = n - right + (right - left + 1) + (left + 1)
		e = n - left + (left + 1)
		f = (n - left) * 2
		g = (right + 1) * 2
		h = right + 1 + (n - right)
		print(max(a, b, c, d, e, f, g, h))
	elif sum(l) == 1:
		ind = l.index(1)
		print(2 * (max(ind, n - ind - 1) + 1))
	else:
		print(n)


import sys, math
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	a = list(input())
	a.pop()
	if '1' in a:
		q = list(a)
		q.reverse()
		w = 2 * (len(a) - q.index('1'))
		qw = 2 * q.index('1')
		print(max(w, 2 * (len(a) - a.index('1')), qw, 2 * a.index('1')))
	else:
		print(len(a))


t = int(input())
for i in range(t):
	num = int(input())
	s = input()
	first = s.find('1')
	last = s.rfind('1')
	dif = min(first, len(s) - 1 - last)
	if dif > -1:
		print((num - dif) * 2)
	else:
		print(num)


t = int(input())
for _ in range(t):
	input()
	s = input()
	if '1' not in s:
		print(len(s))
	elif '0' not in s:
		print(2 * len(s))
	else:
		best = max((s.find('1'), s[::-1].find('1'), s.rfind('1'), s[::-1].rfind('1')))
		print(2 * (best + 1))


def calc(a):
	if 1 not in a:
		return len(a)
	u = a.index(1)
	v = len(a) - a[::-1].index(1) - 1
	ans = (v - u + 1 + max(u, len(a) - v - 1)) * 2
	ans = max(ans, u + len(a) - v - 1 + a.count(1) * 2)
	return ans
for _ in range(int(input())):
	input()
	print(calc(list(map(int, input().strip()))))


import math
t = int(input())
res = []
for _ in range(t):
	n = int(input())
	L = ''.join(input().split())
	r1 = L.find('1')
	r2 = L.rfind('1')
	if r1 == -1:
		res.append(n)
	else:
		if L.count('0') <= 1:
			res.append(n * 2)
			continue
		s1 = max(L.find('1') + 1, n - L.find('1'), L.rfind('1') + 1, n - L.rfind('1')) * 2
		res.append(s1)
for i in res:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(input())
	ans = 0
	b = []
	last = -1
	if '1' not in a:
		print(n)
		continue
	for i in range(n):
		if a[i] == '1':
			b.append(i)
	kek = 0
	for i in range(len(b)):
		if i == 0:
			kek += b[i] + 2
		else:
			kek += b[i] - b[i - 1] + 1
	kek += n - b[-1] - 1
	kek1 = b[-1] + 1 + b[-1] + 1
	kek2 = n - b[0] + (n - b[0])
	print(max(kek, max(kek1, kek2)))


for t in range(int(input())):
	(n, s) = (int(input()), input())
	print(max(n, 2 * max(len(s.lstrip('0')), len(s.rstrip('0')))))


t = int(input())
while t:
	c = 0
	n = int(input())
	s = input()
	strt = n
	end = -1
	for i in range(n):
		if s[i] == '1':
			strt = min([strt, i])
			end = max([end, i])
			c += 1
	if c == 0:
		print(n)
	elif c >= n - 1:
		print(2 * n)
	else:
		x = end - strt + 1 + max([n - 1 - end, strt])
		print(2 * x)
	t -= 1


t = int(input())
for i in range(t):
	a = int(input())
	s = input()
	l = len(s)
	b = s.find('1')
	s = max(l - b, l - s[::-1].find('1'))
	if b == -1:
		print(a)
	else:
		print(2 * s)


q = int(input())
for _ in range(q):
	n = int(input())
	s = input()
	min_pos = -1
	max_pos = -1
	for i in range(n):
		if s[i] == '1':
			max_pos = i
	for i in range(n)[::-1]:
		if s[i] == '1':
			min_pos = i
	if min_pos == -1:
		print(n)
	else:
		print(max(2 * (max_pos + 1), 2 * (n - min_pos)))


T = int(input())
for t in range(T):
	n = int(input())
	s = input()
	a = []
	for i in s:
		a.append(i)
	(right, left) = (0, 0)
	for i in range(len(a)):
		if a[i] == '1':
			right = n - i
			break
	for i in range(len(a) - 1, -1, -1):
		if a[i] == '1':
			left = i + 1
			break
	p = max(left, right)
	ans = 2 * p
	output = max(n, ans)
	print(output)


import sys
import math
import bisect
sys.setrecursionlimit(1000000000)

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())

def modst(a, s):
	res = 1
	while s:
		if s % 2:
			res *= a
		a *= a
		s //= 2
	return res

def size(x1, y1, x2, y2):
	return ((x1 + x2) ** 2 + (y1 + y2) ** 2) ** 0.5

def find(x, f):
	if x == f[x]:
		return x
	else:
		return find(f[x], f)

def nod(a, b):
	while a != b:
		if a > b:
			a = a - b
		else:
			b = b - a
	return a

def rec(a, b):
	(z, x, c, v) = (0, 1, 1, 0)
	while a != 0:
		(q, b, a) = (b // a, a, b % a)
		(c, v) = (v, c - q * v)
		(z, x) = (x, z - q * x)
	return (b, z, c)

def yes(q, w, e, n):
	(z, x, c) = rec(q, w)
	x *= e // z
	c *= e // z
	a = x // (w // z)
	x %= w // z
	c += q // z * a
	z = n - c - x
	if z >= 0:
		print(c, x, z)
	else:
		print(-1)

def main():
	b = iinput()
	s = list(input())
	if '1' in s:
		l = s.index('1')
		s.reverse()
		r = s.index('1')
		if l == r:
			t = max(b - r, l + 1)
			print(t * 2)
		else:
			t = max(b - r, l + 1)
			p = max(t * 2, b + 2)
			t1 = max(b - l, r + 1)
			print(max(p, t1 * 2))
	else:
		print(b)
for i in range(iinput()):
	main()


n = int(input())
for i in range(n):
	m = int(input())
	s = input()
	if not s.find('1') + 1:
		print(m)
	elif s.find('1') + 1 == 1 or s.rfind('1') + 1 == len(s):
		print(m * 2)
	elif s.find('1') + 1 < len(s) - s.rfind('1') + 1:
		print((len(s) + 1 - (s.find('1') + 1)) * 2)
	else:
		print((s.rfind('1') + 1) * 2)


t = int(input())
for i in range(t):
	n = int(input())
	stairs = input()
	if '1' not in stairs:
		print(n)
	else:
		li = stairs.index('1')
		ri = stairs.rindex('1')
		needed_i = max(n - li, ri + 1, n - ri, li + 1)
		print(needed_i * 2)


t = int(input())
for i in range(t):
	alaki = input()
	floor = input()
	anyStair = False
	for index in range(len(floor)):
		if floor[index] == '1':
			anyStair = True
			oneIndex = index
			break
	floor = floor[::-1]
	for index in range(len(floor)):
		if floor[index] == '1':
			anyStair = True
			if index < oneIndex:
				oneIndex = index
	if anyStair == False:
		print(len(floor))
		continue
	oneIndex = len(floor) - oneIndex - 1
	print((oneIndex + 1) * 2)


for i in range(int(input())):
	n = int(input())
	s = input()
	rs = s[::-1]
	if s[0] == '1' or rs[0] == '1':
		print(n * 2)
	elif '1' in s:
		a = s.index('1')
		b = rs.index('1')
		if a > b:
			print((n - b) * 2)
		else:
			print((n - a) * 2)
	else:
		print(n)


def indx(n, s):
	for i in range(n // 2 + 1):
		if s[i] == '1' or s[n - i - 1] == '1':
			return i
	return -1
tests = ['010', '0100', '1', '00000010', '0000000', '1111111', '00100', '001000']
for _ in range(int(input())):
	n = int(input())
	s = input()
	i = indx(n, s)
	if i == -1:
		print(n)
	else:
		print(2 * n - 2 * i)


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	if len(set(s)) == 1:
		if s[0] == '0':
			print(n)
		else:
			print(2 * n)
	else:
		start = s.index('1')
		last = s[::-1].index('1')
		print(2 * n - 2 * min(start, last))


for _ in range(int(input())):
	n = int(input())
	s = input()
	s = list(s)
	if '1' in s:
		i1 = n - s.index('1')
		s.reverse()
		i2 = n - s.index('1')
		print(max(i1 * 2, i2 * 2, n))
	else:
		print(n)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	l = len(s)
	m = -1
	p = -1
	for i in range(l):
		if s[i] == '1':
			p = i
			if m == -1:
				m = i
	d = 2 * (n - m)
	e = 2 * m
	if e > d:
		d = e
	e = 2 * (p + 1)
	f = 2 * (n - p)
	if f > e:
		e = f
	if e > d:
		d = e
	if m == -1 or d < n:
		d = n
	print(d)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	if a.count('1') == 0:
		print(n)
	else:
		first = a.index('1')
		last = a.rindex('1')
		before = n - first
		after = n - last
		prelast1 = first + 1
		prelast2 = last + 1
		max1 = max(before, last, prelast1, prelast2)
		print(max1 * 2)


n = int(input())
for i in range(n):
	k = int(input())
	l = input()
	ones = 0
	calc = -1
	j = 0
	for el in l:
		j += 1
		if el == '1':
			ones += 1
			if ones == 1:
				calc = j
			calcl = j
	if ones == 0:
		print(k)
	elif ones == 1:
		print(max(calc + calc, (k - calc + 1) * 2))
	else:
		print(max(calcl + calcl, (k - calc + 1) * 2))


def add_one(the_list):
	x = len(the_list)
	j = the_list.index('1')
	l = the_list[::-1]
	n = l.index('1')
	y = min(j, n)
	return (x - y) * 2
z = int(input())
m = 0
for i in range(z):
	c = int(input())
	v = input()
	if '1' in v:
		print(int(add_one(v)))
	else:
		print(c)


for _ in range(int(input())):
	n = int(input())
	a = input()
	print((n - min(a[::-1].find('1'), a.find('1'))) * 2 if '1' in a else n)


for i in range(int(input())):
	n = int(input())
	s = list(input())
	if '1' in s:
		index1 = n - s.index('1')
		s.reverse()
		index2 = n - s.index('1')
		print(max(index1 * 2, index2 * 2, n))
	else:
		print(n)


t = int(input())
while t != 0:
	n = int(input())
	s = str(input())
	maxi = 0
	ln = len(s) - 1
	for i in range(0, len(s)):
		if s[i] == '1':
			maxi = max(maxi, i - 0 + 1, ln - i + 1)
	if maxi == 0:
		print(len(s))
	else:
		print(maxi * 2)
	t -= 1


t = int(input())
for j in range(t):
	n = int(input())
	a = list(input())
	x = 0
	y = 0
	f = 0
	for i in range(n):
		if a[i] == '1':
			x = i
			f = 1
			break
	for i in range(n - 1, -1, -1):
		if a[i] == '1':
			y = n - i - 1
			f = 1
			break
	if f:
		print(max(x + 2 * sum(list(map(int, a))) + y, 2 * x + 2, 2 * y + 2, 2 * (n - x), 2 * (n - y)))
	else:
		print(n)


t = int(input())
while t:
	n = int(input())
	m = input()
	k = 0
	j = n
	l = 1
	a = 0
	d = 0
	for b in m[:]:
		if b == '1' and l <= n // 2:
			k = 1
			a = 2 * (n - l + 1)
			break
		l += 1
	for i in m[::-1]:
		if i == '1' and j > n // 2:
			k = 1
			d = 2 * j
			break
		j -= 1
	if k == 0:
		print(n)
	elif a > d:
		print(a)
	else:
		print(d)
	t -= 1


t = int(input())
while t > 0:
	p = int(input())
	s = input()
	if s.count('1') == 0:
		print(p)
	else:
		(a, b) = (s.index('1'), s[::-1].index('1'))
		print(2 * (p - min(a, b)))
	t -= 1


def solve_a():
	(l_nr, s_nr, pencap, pensilcap, policap) = (int(x) for x in input().split())
	pennr = (l_nr + pencap - 1) // pencap
	pensil_nr = (s_nr + pensilcap - 1) // pensilcap
	if pennr + pensil_nr > policap:
		print(-1)
	else:
		print(pennr, pensil_nr)

def solve_b():
	floor_size = int(input())
	floor_map = input()

	def find1(s):
		for (i, elem) in enumerate(s):
			if elem == '1':
				return i
		return -1
	lmost1 = find1(floor_map)
	if lmost1 == -1:
		print(floor_size)
		return
	ans = 2 * (floor_size - lmost1)
	rmost1 = find1(floor_map[::-1])
	ans = max(ans, 2 * (floor_size - rmost1))
	print(ans)
t = int(input())
for _ in range(t):
	solve_b()


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	if s == '0' * n:
		print(n)
	else:
		c = 0
		for i in s:
			c += 1
			if i == '1':
				break
		d = 0
		for i in range(len(s) - 1, -1, -1):
			j = s[i]
			d += 1
			if j == '1':
				break
		print(2 * (n - min(c, d) + 1))


t = int(input())
for test in range(t):
	n = int(input())
	s = input()
	first = n + 1
	last = 0
	ones = 0
	for i in range(n):
		if s[i] == '1':
			first = min(first, i)
			last = max(last, i)
			ones += 1
	if ones == 0:
		print(n)
	else:
		start = max(last, n - first - 1)
		print(2 * (start + 1))


t = int(input())
for test in range(t):
	rooms = int(input())
	stairs = input()
	nVertice = rooms * 2 + 1
	if rooms == 1:
		if stairs[0] == '1':
			print(2)
		else:
			print(1)
	elif stairs[0] == '1' or stairs[-1] == '1':
		print(rooms * 2)
	else:
		minI = rooms
		maxI = 0
		um = 0
		for i in range(1, rooms + 1):
			if stairs[i - 1] == '1':
				if i < minI:
					minI = i
				if i > maxI:
					maxI = i
				um += 1
		if um == 0:
			print(rooms)
		else:
			minI -= 1
			if rooms - minI >= maxI:
				print(rooms * 2 - minI * 2)
			else:
				print(maxI * 2)


q = int(input())
for i in range(q):
	a = int(input())
	b = input()
	b = list(b)
	c = b[::-1]
	z = b.count('1')
	if z == 0:
		print(a)
	else:
		d = b.index('1')
		e = c.index('1')
		if d >= e:
			print(2 * (a - e))
		else:
			print(2 * (a - d))


def inp_n():
	return int(input())

def inp_list():
	return list(map(int, input().split()))

def inp_mul_num():
	return map(int, input().split())

def is_odd(n):
	if n & 1:
		return True
	return False
from collections import defaultdict
for _ in range(inp_n()):
	n = inp_n()
	s = input()
	(ind1, ind2) = (-1, -1)
	l = sorted(s)
	if l[0] == l[-1] and l[0] == '0':
		print(n)
	elif l[0] == l[-1] and l[0] == '1':
		print(2 * n)
	else:
		for i in range(n):
			if s[i] == '1':
				ind1 = i
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				ind2 = i
				break
		m = max(n - 1 - ind1, ind2)
		print(2 * (m + 1))


import math
t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	s = input()
	l = list(s)
	pos1 = 0
	pos2 = 0
	for i in range(len(l)):
		if l[i] == '1':
			pos1 = i + 1
			break
	ans1 = 2 * (n - pos1 + 1)
	for i in range(len(l) - 1, -1, -1):
		if l[i] == '1':
			pos2 = i + 1
			break
	ans2 = 2 * pos2
	if l.count('1') == 0:
		print(n)
	else:
		print(max(ans1, ans2))


import math
t = int(input())
for i in range(t):
	cnt = -1
	cnt2 = -1
	flag = True
	flag2 = True
	siz = int(input())
	line = input()
	if line[0] == '1' or line[siz - 1] == '1':
		print(siz * 2)
	else:
		for j in range(siz):
			if line[j] == '1' and flag == True:
				cnt = j
				cnt = siz - cnt
				cnt = cnt * 2
				flag = False
		for j in range(siz - 1, -1, -1):
			if line[j] == '1' and flag2 == True:
				cnt2 = j + 1
				cnt2 = cnt2 * 2
				flag2 = False
		if cnt != -1:
			print(max(cnt, cnt2))
		else:
			print(siz)


import sys
import itertools
n = None
total = None

def solution(rooms):
	ans = None
	size = len(rooms)
	for (pos, room) in zip(itertools.count(), rooms):
		if room == 1:
			r = min(pos, size - pos - 1)
			if ans is None or r < ans:
				ans = r
	if ans is None:
		return size
	else:
		return (size - ans) * 2
for (line_num, line) in zip(itertools.count(), sys.stdin):
	if line_num == 0:
		total = int(line)
	elif line_num == (total + 1) * 2:
		break
	elif line_num % 2 == 1:
		n = int(line)
	else:
		rooms = list(map(int, line.strip('\n')))
		print(solution(rooms))