There are n villages in a Chefland. Some of the villages have electricity facilities, other doesn't. You can consider the villages arranged in line in the order 1 to n from left to right. i-th of village can be considered at xi coordinates.

Chef decided that electricity should be provided to all the villages. So, he decides to buy some amount of electric wires to connect the villeges without electricity to some villages with electricity. As Chef does not want to spend too much amount of money on wires, can you find out minimum amount of length of wire Chef should buy.

-----Input-----
First line of the input contains an integer T denoting the number of test cases. T test cases follow.
First line of each test case contains an integer n denoting number of villages in Chefland.
Second line will contain a string of length n containing '0' or '1's only. If i-th character of the string is '1', then it denotes that i-th village has electricity.
Next line contains n space separated integers denoting the x coordinates of the villages in the order from village 1 to n

-----Output-----
For each test case, output a single line containing a integer corresponding to the minimum length of wire Chef needs to buy.

-----Constraints-----
- 1 ≤ T ≤ 10
- It is guaranteed that there will be at least one village which will have electricity.
- 1 ≤ x1 <  x2 <  ... < xn ≤ 109

-----Subtasks-----
Subtask #1 : 30 points
- 1 ≤ N ≤ 1000

Subtask #2 : 70 points
- 1 ≤ N ≤ 105

-----Example-----
Input
2
2
01
1 2
3
100
1 5 6
Output:
1
5

-----Explanation-----
In the first example, first village does not have electricity. If we put a wire between village 1 and 2 of length 1, then both the villages will have electricity.

In the second example,
We can a draw a wire from first village to third village, passing through second village. Its total length will be 5. Now all the villages will have electricity. This is the minimum length of wire you will require.

Difficulty: interview

Starter code:

Solutions:
for _ in range(int(input())):
 n=int(input())
 s=list(input())
 coord=list(map(int,input().split()))
 p=0
 i=0
 h=[]
 for i in range(0,n):
  if s[i]=='1':
   h.append(i)
 if h[0]!=0:
  p=p+coord[h[0]]-coord[0]
 if h[len(h)-1]!=n-1:
  p=p+coord[n-1]-coord[h[len(h)-1]]
 for j in range(0,len(h)-1):
  if h[j]+1==h[j+1]:
   continue
  if h[j+1]-h[j]-1==1:
   p=p+min(coord[h[j]+1]-coord[h[j]],coord[h[j+1]]-coord[h[j]+1])
  else:
   y=min(coord[h[j+1]]-coord[h[j]+1],coord[h[j+1]-1]-coord[h[j]])
   for k in range(h[j]+1,h[j+1]-1):
    y=min(y,coord[k]-coord[h[j]]+coord[h[j+1]]-coord[k+1])
   p=p+y
 print(p)


for _ in range(int(input())):
 n=int(input())
 s=list(input())
 l=list(map(int,input().split()))
 p=0
 i=0
 h=[]
 for i in range(0,n):
  if s[i]=='1':
   h.append(i)
 if h[0]!=0:
  p=p+l[h[0]]-l[0]
 if h[len(h)-1]!=n-1:
  p=p+l[n-1]-l[h[len(h)-1]]
 for j in range(0,len(h)-1):
  if h[j]+1==h[j+1]:
   continue
  if h[j+1]-h[j]-1==1:
   p=p+min(l[h[j]+1]-l[h[j]],l[h[j+1]]-l[h[j]+1])
  else:
   y=min(l[h[j+1]]-l[h[j]+1],l[h[j+1]-1]-l[h[j]])
   for k in range(h[j]+1,h[j+1]-1):
    y=min(y,l[k]-l[h[j]]+l[h[j+1]]-l[k+1])
   p=p+y
 print(p)

for _ in range(int(input())):
 n=int(input())
 s=list(input())
 l=list(map(int,input().split()))
 p=0
 i=0
 h=[]
 for i in range(0,n):
  if s[i]=='1':
   h.append(i)
 if h[0]!=0:
  p=p+l[h[0]]-l[0]
 if h[len(h)-1]!=n-1:
  p=p+l[n-1]-l[h[len(h)-1]]
 for j in range(0,len(h)-1):
  if h[j]+1==h[j+1]:
   continue
  if h[j+1]-h[j]-1==1:
   p=p+min(l[h[j]+1]-l[h[j]],l[h[j+1]]-l[h[j]+1])
  else:
   y=min(l[h[j+1]]-l[h[j]+1],l[h[j+1]-1]-l[h[j]])
   for k in range(h[j]+1,h[j+1]-1):
    y=min(y,l[k]-l[h[j]]+l[h[j+1]]-l[k+1])
   p=p+y
 print(p)
 


for _ in range(int(input())):
 n=int(input())
 s=list(input())
 l=list(map(int,input().split()))
 p=0
 i=0
 h=[]
 for i in range(0,n):
  if s[i]=='1':
   h.append(i)
 if h[0]!=0:
  p=p+l[h[0]]-l[0]
 if h[len(h)-1]!=n-1:
  p=p+l[n-1]-l[h[len(h)-1]]
 for j in range(0,len(h)-1):
  if h[j]+1==h[j+1]:
   continue
  if h[j+1]-h[j]-1==1:
   p=p+min(l[h[j]+1]-l[h[j]],l[h[j+1]]-l[h[j]+1])
  else:
   y=min(l[h[j+1]]-l[h[j]+1],l[h[j+1]-1]-l[h[j]])
   for k in range(h[j]+1,h[j+1]-1):
    y=min(y,l[k]-l[h[j]]+l[h[j+1]]-l[k+1])
   p=p+y
 print(p)

for _ in range(int(input())):
 n=int(input())
 s=list(input())
 l=list(map(int,input().split()))
 p=0
 i=0
 h=[]
 for i in range(0,n):
  if s[i]=='1':
   h.append(i)
 if h[0]!=0:
  p=p+l[h[0]]-l[0]
 if h[len(h)-1]!=n-1:
  p=p+l[n-1]-l[h[len(h)-1]]
 for j in range(0,len(h)-1):
  if h[j]+1==h[j+1]:
   continue
  if h[j+1]-h[j]-1==1:
   p=p+min(l[h[j]+1]-l[h[j]],l[h[j+1]]-l[h[j]+1])
  else:
   y=min(l[h[j+1]]-l[h[j]+1],l[h[j+1]-1]-l[h[j]])
   for k in range(h[j]+1,h[j+1]-1):
    y=min(y,l[k]-l[h[j]]+l[h[j+1]]-l[k+1])
   p=p+y
 print(p)

for _ in range(int(input())):
 n=int(input())
 s=list(input())
 l=list(map(int,input().split()))
 p=0
 i=0
 h=[]
 for i in range(0,n):
  if s[i]=='1':
   h.append(i)
 if h[0]!=0:
  p=p+l[h[0]]-l[0]
 if h[len(h)-1]!=n-1:
  p=p+l[n-1]-l[h[len(h)-1]]
 for j in range(0,len(h)-1):
  if h[j]+1==h[j+1]:
   continue
  if h[j+1]-h[j]-1==1:
   p=p+min(l[h[j]+1]-l[h[j]],l[h[j+1]]-l[h[j]+1])
  else:
   y=min(l[h[j+1]]-l[h[j]+1],l[h[j+1]-1]-l[h[j]])
   for k in range(h[j]+1,h[j+1]-1):
    y=min(y,l[k]-l[h[j]]+l[h[j+1]]-l[k+1])
   p=p+y
 print(p)
    
   
   


# cook your dish here
t = int(input())
ret = []
while t>0:
 t -= 1
 n = int(input())
 s = input()
 arr = list(map(int,input().split(' ')))
 l = []
 f = True
 for i in range(len(arr)):
  if s[i]=='1':
   if f:
    fr = i
    f = False
   l.append(i)
 
 r = []
 for i in range(1,len(l)):
  r.append([l[i-1],l[i]])
 
 # i = fr+1
 ans = 0
 for a in r:
  x = a[0]
  i = x+1
  y = a[1]
  curr = arr[i]-arr[x]
  while i<=y:
   if arr[i]-arr[i-1]>curr:
    curr = arr[i]-arr[i-1]
   i += 1
  ans += abs(arr[y]-arr[x])
  ans -= curr
 ans += arr[fr]-arr[0]
 ans += arr[len(arr)-1]-arr[l[len(l)-1]]
 
 ret.append(ans)
for i in ret:
 print(i)


# cook your dish here
t = int(input())
for _ in range(t):
 n = int(input())
 s = input()
 x = [int(i) for i in input().split()]
 y=0
 z=0
 l=0; k=0
 d = {}
 for i in range(len(s)):
  if s[i] == '1':
   d[y] = i
   y = y+1
   
 ln = y
 if(d[0]!=0):
  i = d[0]
  l = x[i] - x[0]
 
   
 for i in range(ln-1):
  y = d[i]
  z = d[i+1]
  max = -90
  for j in range(d[i]+1, d[i+1]+1):
   if(max<(x[j] - x[j-1])):
    max = x[j]-x[j-1]
   
  l = l + (x[z]-x[y]) - max
   
 if(d[ln-1] != n-1):
  i = d[ln-1]
  l = l + (x[n-1] - x[i])
 
 
 print(l)