q=[]
t=int(input())
ch = 0
for i in range (t):
    ch = 0
    n=int(input())
    s=input()
    if (('<'in s) and ('>' in s)):
        if s[0] == '-':
            ch=ch+2
        for j in range (1,len(s)-1):
            if s[j] == '-':
                if s[j-1] == '-':
                    ch=+1
                else:
                    ch=+2
        if s[(len(s)-1)] =='-':
            if s[(len(s)-2)] == '-' and s[0] == '-':
                ch=ch+0
            elif s[len(s)-2] == '-' or s[0] == '-':
                ch=ch+1
            else:
                ch=ch+2
    else:
        ch = n
    q.append(ch)
for i in range(len(q)):
    print(q[i])


q=[]
t=int(input())
ch = 0
for i in range (t):
    ch = 0
    n=int(input())
    s=input()
    if (('<'in s) and ('>' in s)):
        if s[0] == '-':
            ch=ch+2
        for j in range (1,len(s)-1):
            if s[j] == '-':
                if s[j-1] == '-':
                    ch=ch+1
                else:
                    ch=ch+2
        if s[(len(s)-1)] =='-':
            if s[(len(s)-2)] == '-' and s[0] == '-':
                ch=ch+0
            elif s[len(s)-2] == '-' or s[0] == '-':
                ch=ch+1
            else:
                ch=ch+2
    else:
        ch = n
    q.append(ch)
for i in range(len(q)):
    print(q[i])


import math
t = int(input())
q=[]
a=1
b=0
b = False
for i in range (t):
    b=0
    b = False
    a = 1
    n=int(input())
    s = input()
    if s == '<>':
        q.append(0)
        continue
    if (s[0]=='>' and s[n-1]=='<')or(s[0]=='<' and s[n-1]=='>'):
        b = True
    for j in range(len(s)-1):
        if (s[j]=='>') and (s[j+1]=='<') or (s[j]=='<') and (s[j+1]=='>'):
            b = True
    if b == True:
        for w in range(len(s)):
            if s[w] == '-':
                a=a+1;
        if a == 1:
            q.append(0)
        else:
            q.append(a)
    if b == False:
        if (('<' in s) and ('>' in s)):
            for r in range(len(s)-1):
                if(s[r]=='>' and s[r+1]=='>')or(s[r]=='<' and s[r+1]=='<')or(s[0]=='>' and s[n-1]=='>')or(s[0]=='<' and s[n-1]=='<'):
                    b=b+1
            q.append(n-b)
        else:
            q.append(n)
for i in range (t):
    print(q[i])


import math
t = int(input())
q=[]
a=1
b=0
b = False
for i in range (t):
    b=0
    b = False
    a = 1
    n=int(input())
    s = input()
    if s == '<>':
        q.append(0)
        continue
    if (s[0]=='>' and s[n-1]=='<')or(s[0]=='<' and s[n-1]=='>'):
        b = True
    for j in range(len(s)-1):
        if (s[j]=='>') and (s[j+1]=='<') or (s[j]=='<') and (s[j+1]=='>'):
            b = True
    if b == True:
        for w in range(len(s)):
            if s[w] == '-':
                a=a+1;
        q.append(a)
    if b == False:
        if ('<' in s and '>' in s):
            for r in range(len(s)-1):
                if(s[r]=='>' and s[r+1]=='>')or(s[r]=='<' and s[r+1]=='<'):
                    b=b+1
            q.append(n-b)
        else:
            q.append(n)
for i in range (t):
    print(q[i])


import math
t = int(input())
q=[]
a=1
b=0
b = False
for i in range (t):
    b=0
    b = False
    a = 1
    n=int(input())
    s = input()
    if s == '<>':
        q.append(0)
        continue
    if (s[0]=='>' and s[n-1]=='<')or(s[0]=='<' and s[n-1]=='>'):
        b = True
    for j in range(len(s)-1):
        if (s[j]=='>') and (s[j+1]=='<') or (s[j]=='<') and (s[j+1]=='>'):
            b = True
    if b == True:
        for w in range(len(s)):
            if s[w] == '-':
                a=a+1;
        q.append(a)
    if b == False:
        if ('<' in s and '>' in s):
            for r in range(len(s)-1):
                if(s[r]=='>' and s[r+1]=='>')or(s[r]=='<' and s[r+1]=='<')or(s[0]=='>' and s[n-1]=='>')or(s[0]=='<' and s[n-1]=='<'):
                    b=b+1
            q.append(n-b)
        else:
            q.append(n)
for i in range (t):
    print(q[i])


import math
t = int(input())
q=[]
a=1
b = False
for i in range (t):
    b = False
    a = 1
    n=int(input())
    s = input()
    if s == '<>':
        q.append(0)
        continue
    for j in range(len(s)-1):
        if ((s[j]=='>') and (s[j+1]=='<')) or ((s[j]=='<') and (s[j+1]=='>')):
            b = True
    if b == True:
        for w in range(len(s)):
            if s[w] == '-':
                a=a+1;
        q.append(a)
    if b == False:
        q.append(len(s))
for i in range (t):
    print(q[i])


import math
t = int(input())
q=[]
a=1
b = False
for i in range (t):
    b = False
    a = 1
    n=int(input())
    s = input()
    if s == '<>':
        q.append(0)
        continue
    if (s[0]=='>' and s[n-1]=='<')or(s[0]=='<' and s[n-1]=='>'):
        b = True
    for j in range(len(s)-1):
        if (s[j]=='>') and (s[j+1]=='<') or (s[j]=='<') and (s[j+1]=='>'):
            b = True
    if b == True:
        for w in range(len(s)):
            if s[w] == '-':
                a=a+1;
        q.append(a)
    if b == False:
        q.append(len(s))
for i in range (t):
    print(q[i])


# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations  # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
# If the element is already present in the list,

# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect

# If the element is already present in the list,
# the right most position where element has to be inserted is returned

# ==============================================================================================
# fast I/O region

BUFSIZE = 8192
from sys import stderr

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):
    """Prints the values to a stream, or to sys.stdout by default."""
    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)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType

def iterative(f, stack=[]):
    print(stack)
    def wrapped_func(*args, **kwargs):
        if stack: return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
                continue
            stack.pop()
            if not stack: break
            to = stack[-1].send(to)
        return to

    return wrapped_func

#### END ITERATE RECURSION ####

# ===============================================================================================
# some shortcuts

mod = 1000000007

def inp(): return sys.stdin.readline().rstrip("\r\n")  # for fast input

def out(var): sys.stdout.write(str(var))  # for fast output, always take string

def lis(): return list(map(int, inp().split()))

def stringlis(): return list(map(str, inp().split()))

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

def strsep(): return map(str, inp().split())

def fsep(): return map(float, inp().split())

def nextline(): out("\n")  # as stdout.write always print sring.

def testcase(t):
    for p in range(t):
        solve()

def pow(x, y, p):
    res = 1  # Initialize result
    x = x % p  # Update x if it is more , than or equal to p
    if (x == 0):
        return 0
    while (y > 0):
        if ((y & 1) == 1):  # If y is odd, multiply, x with result
            res = (res * x) % p

        y = y >> 1  # y = y/2
        x = (x * x) % p
    return res

from functools import reduce

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)))

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

#discrete binary search
#minimise:
    # def search():
    #     l = 0
    #     r = 10 ** 15
    #
    #     for i in range(200):
    #         if isvalid(l):
    #             return l
    #         if l == r:
    #             return l
    #         m = (l + r) // 2
    #         if isvalid(m) and not isvalid(m - 1):
    #             return m
    #         if isvalid(m):
    #             r = m + 1
    #         else:
    #             l = m
    #     return m

#maximise:
    # def search():
    #     l = 0
    #     r = 10 ** 15
    #
    #     for i in range(200):
    #         # print(l,r)
    #         if isvalid(r):
    #             return r
    #         if l == r:
    #             return l
    #         m = (l + r) // 2
    #         if isvalid(m) and not isvalid(m + 1):
    #             return m
    #         if isvalid(m):
    #             l = m
    #         else:
    #             r = m - 1
    #     return m

##to find factorial and ncr
# N=100000
# mod = 10**9 +7
# fac = [1, 1]
# finv = [1, 1]
# inv = [0, 1]
#
# for i in range(2, N + 1):
#     fac.append((fac[-1] * i) % mod)
#     inv.append(mod - (inv[mod % i] * (mod // i) % mod))
#     finv.append(finv[-1] * inv[-1] % mod)
#
#
# def comb(n, r):
#     if n < r:
#         return 0
#     else:
#         return fac[n] * (finv[r] * finv[n - r] % mod) % mod

##############Find sum of product of subsets of size k in a array
# ar=[0,1,2,3]
# k=3
# n=len(ar)-1
# dp=[0]*(n+1)
# dp[0]=1
# for pos in range(1,n+1):
#     dp[pos]=0
#     l=max(1,k+pos-n-1)
#     for j in range(min(pos,k),l-1,-1):
#         dp[j]=dp[j]+ar[pos]*dp[j-1]
# print(dp[k])

def prefix_sum(ar):  # [1,2,3,4]->[1,3,6,10]
    return list(accumulate(ar))

def suffix_sum(ar):  # [1,2,3,4]->[10,9,7,4]
    return list(accumulate(ar[::-1]))[::-1]

def N():
    return int(inp())

# =========================================================================================
from collections import defaultdict

def numberOfSetBits(i):
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

def solve():
    s=inp()
    n=len(s)
    ca=0
    cb=0
    c=0
    for i in range(n-1,-1,-1):
        if s[i]=="A":
            ca+=1
            if cb>0:
                cb-=1
                ca-=1
        else:
            cb+=1
    print(cb%2 + ca)

# solve()
testcase(int(inp()))


# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations  # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
# If the element is already present in the list,

# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect

# If the element is already present in the list,
# the right most position where element has to be inserted is returned

# ==============================================================================================
# fast I/O region

BUFSIZE = 8192
from sys import stderr

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):
    """Prints the values to a stream, or to sys.stdout by default."""
    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)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType

def iterative(f, stack=[]):
    print(stack)
    def wrapped_func(*args, **kwargs):
        if stack: return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
                continue
            stack.pop()
            if not stack: break
            to = stack[-1].send(to)
        return to

    return wrapped_func

#### END ITERATE RECURSION ####

# ===============================================================================================
# some shortcuts

mod = 1000000007

def inp(): return sys.stdin.readline().rstrip("\r\n")  # for fast input

def out(var): sys.stdout.write(str(var))  # for fast output, always take string

def lis(): return list(map(int, inp().split()))

def stringlis(): return list(map(str, inp().split()))

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

def strsep(): return map(str, inp().split())

def fsep(): return map(float, inp().split())

def nextline(): out("\n")  # as stdout.write always print sring.

def testcase(t):
    for p in range(t):
        solve()

def pow(x, y, p):
    res = 1  # Initialize result
    x = x % p  # Update x if it is more , than or equal to p
    if (x == 0):
        return 0
    while (y > 0):
        if ((y & 1) == 1):  # If y is odd, multiply, x with result
            res = (res * x) % p

        y = y >> 1  # y = y/2
        x = (x * x) % p
    return res

from functools import reduce

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)))

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

#discrete binary search
#minimise:
    # def search():
    #     l = 0
    #     r = 10 ** 15
    #
    #     for i in range(200):
    #         if isvalid(l):
    #             return l
    #         if l == r:
    #             return l
    #         m = (l + r) // 2
    #         if isvalid(m) and not isvalid(m - 1):
    #             return m
    #         if isvalid(m):
    #             r = m + 1
    #         else:
    #             l = m
    #     return m

#maximise:
    # def search():
    #     l = 0
    #     r = 10 ** 15
    #
    #     for i in range(200):
    #         # print(l,r)
    #         if isvalid(r):
    #             return r
    #         if l == r:
    #             return l
    #         m = (l + r) // 2
    #         if isvalid(m) and not isvalid(m + 1):
    #             return m
    #         if isvalid(m):
    #             l = m
    #         else:
    #             r = m - 1
    #     return m

##to find factorial and ncr
# N=100000
# mod = 10**9 +7
# fac = [1, 1]
# finv = [1, 1]
# inv = [0, 1]
#
# for i in range(2, N + 1):
#     fac.append((fac[-1] * i) % mod)
#     inv.append(mod - (inv[mod % i] * (mod // i) % mod))
#     finv.append(finv[-1] * inv[-1] % mod)
#
#
# def comb(n, r):
#     if n < r:
#         return 0
#     else:
#         return fac[n] * (finv[r] * finv[n - r] % mod) % mod

##############Find sum of product of subsets of size k in a array
# ar=[0,1,2,3]
# k=3
# n=len(ar)-1
# dp=[0]*(n+1)
# dp[0]=1
# for pos in range(1,n+1):
#     dp[pos]=0
#     l=max(1,k+pos-n-1)
#     for j in range(min(pos,k),l-1,-1):
#         dp[j]=dp[j]+ar[pos]*dp[j-1]
# print(dp[k])

def prefix_sum(ar):  # [1,2,3,4]->[1,3,6,10]
    return list(accumulate(ar))

def suffix_sum(ar):  # [1,2,3,4]->[10,9,7,4]
    return list(accumulate(ar[::-1]))[::-1]

def N():
    return int(inp())

# =========================================================================================
from collections import defaultdict

def numberOfSetBits(i):
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

def solve():
    n=N()
    s=inp()
    c_=0
    if s=='<'*n or s==">"*n or s=="-"*n:
        print(n)
        return
    for i in range(n):
        if s[i]=="-" or s[(i-1+n)%n]=="-":
            c_+=1
    print(c_)

# solve()
testcase(int(inp()))


# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations  # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
# If the element is already present in the list,

# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect

# If the element is already present in the list,
# the right most position where element has to be inserted is returned

# ==============================================================================================
# fast I/O region

BUFSIZE = 8192
from sys import stderr

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):
    """Prints the values to a stream, or to sys.stdout by default."""
    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)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType

def iterative(f, stack=[]):
    print(stack)
    def wrapped_func(*args, **kwargs):
        if stack: return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
                continue
            stack.pop()
            if not stack: break
            to = stack[-1].send(to)
        return to

    return wrapped_func

#### END ITERATE RECURSION ####

# ===============================================================================================
# some shortcuts

mod = 1000000007

def inp(): return sys.stdin.readline().rstrip("\r\n")  # for fast input

def out(var): sys.stdout.write(str(var))  # for fast output, always take string

def lis(): return list(map(int, inp().split()))

def stringlis(): return list(map(str, inp().split()))

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

def strsep(): return map(str, inp().split())

def fsep(): return map(float, inp().split())

def nextline(): out("\n")  # as stdout.write always print sring.

def testcase(t):
    for p in range(t):
        solve()

def pow(x, y, p):
    res = 1  # Initialize result
    x = x % p  # Update x if it is more , than or equal to p
    if (x == 0):
        return 0
    while (y > 0):
        if ((y & 1) == 1):  # If y is odd, multiply, x with result
            res = (res * x) % p

        y = y >> 1  # y = y/2
        x = (x * x) % p
    return res

from functools import reduce

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)))

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

#discrete binary search
#minimise:
    # def search():
    #     l = 0
    #     r = 10 ** 15
    #
    #     for i in range(200):
    #         if isvalid(l):
    #             return l
    #         if l == r:
    #             return l
    #         m = (l + r) // 2
    #         if isvalid(m) and not isvalid(m - 1):
    #             return m
    #         if isvalid(m):
    #             r = m + 1
    #         else:
    #             l = m
    #     return m

#maximise:
    # def search():
    #     l = 0
    #     r = 10 ** 15
    #
    #     for i in range(200):
    #         # print(l,r)
    #         if isvalid(r):
    #             return r
    #         if l == r:
    #             return l
    #         m = (l + r) // 2
    #         if isvalid(m) and not isvalid(m + 1):
    #             return m
    #         if isvalid(m):
    #             l = m
    #         else:
    #             r = m - 1
    #     return m

##to find factorial and ncr
# N=100000
# mod = 10**9 +7
# fac = [1, 1]
# finv = [1, 1]
# inv = [0, 1]
#
# for i in range(2, N + 1):
#     fac.append((fac[-1] * i) % mod)
#     inv.append(mod - (inv[mod % i] * (mod // i) % mod))
#     finv.append(finv[-1] * inv[-1] % mod)
#
#
# def comb(n, r):
#     if n < r:
#         return 0
#     else:
#         return fac[n] * (finv[r] * finv[n - r] % mod) % mod

##############Find sum of product of subsets of size k in a array
# ar=[0,1,2,3]
# k=3
# n=len(ar)-1
# dp=[0]*(n+1)
# dp[0]=1
# for pos in range(1,n+1):
#     dp[pos]=0
#     l=max(1,k+pos-n-1)
#     for j in range(min(pos,k),l-1,-1):
#         dp[j]=dp[j]+ar[pos]*dp[j-1]
# print(dp[k])

def prefix_sum(ar):  # [1,2,3,4]->[1,3,6,10]
    return list(accumulate(ar))

def suffix_sum(ar):  # [1,2,3,4]->[10,9,7,4]
    return list(accumulate(ar[::-1]))[::-1]

def N():
    return int(inp())

# =========================================================================================
from collections import defaultdict

def numberOfSetBits(i):
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

def solve():
    n=N()
    s=inp()
    c_=0
    if s=='<'*n or s==">"*n or s=="-"*n:
        print(n)
        return
    se=set()
    for i in range(n):
        if s[i]=="-":
            se.add(i)
            se.add((i+1)%n)
    print(len(se))

# solve()
testcase(int(inp()))


# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations  # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
# If the element is already present in the list,

# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect

# If the element is already present in the list,
# the right most position where element has to be inserted is returned

# ==============================================================================================
# fast I/O region

BUFSIZE = 8192
from sys import stderr

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):
    """Prints the values to a stream, or to sys.stdout by default."""
    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)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType

def iterative(f, stack=[]):
    print(stack)
    def wrapped_func(*args, **kwargs):
        if stack: return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
                continue
            stack.pop()
            if not stack: break
            to = stack[-1].send(to)
        return to

    return wrapped_func

#### END ITERATE RECURSION ####

# ===============================================================================================
# some shortcuts

mod = 1000000007

def inp(): return sys.stdin.readline().rstrip("\r\n")  # for fast input

def out(var): sys.stdout.write(str(var))  # for fast output, always take string

def lis(): return list(map(int, inp().split()))

def stringlis(): return list(map(str, inp().split()))

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

def strsep(): return map(str, inp().split())

def fsep(): return map(float, inp().split())

def nextline(): out("\n")  # as stdout.write always print sring.

def testcase(t):
    for p in range(t):
        solve()

def pow(x, y, p):
    res = 1  # Initialize result
    x = x % p  # Update x if it is more , than or equal to p
    if (x == 0):
        return 0
    while (y > 0):
        if ((y & 1) == 1):  # If y is odd, multiply, x with result
            res = (res * x) % p

        y = y >> 1  # y = y/2
        x = (x * x) % p
    return res

from functools import reduce

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)))

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

#discrete binary search
#minimise:
    # def search():
    #     l = 0
    #     r = 10 ** 15
    #
    #     for i in range(200):
    #         if isvalid(l):
    #             return l
    #         if l == r:
    #             return l
    #         m = (l + r) // 2
    #         if isvalid(m) and not isvalid(m - 1):
    #             return m
    #         if isvalid(m):
    #             r = m + 1
    #         else:
    #             l = m
    #     return m

#maximise:
    # def search():
    #     l = 0
    #     r = 10 ** 15
    #
    #     for i in range(200):
    #         # print(l,r)
    #         if isvalid(r):
    #             return r
    #         if l == r:
    #             return l
    #         m = (l + r) // 2
    #         if isvalid(m) and not isvalid(m + 1):
    #             return m
    #         if isvalid(m):
    #             l = m
    #         else:
    #             r = m - 1
    #     return m

##to find factorial and ncr
# N=100000
# mod = 10**9 +7
# fac = [1, 1]
# finv = [1, 1]
# inv = [0, 1]
#
# for i in range(2, N + 1):
#     fac.append((fac[-1] * i) % mod)
#     inv.append(mod - (inv[mod % i] * (mod // i) % mod))
#     finv.append(finv[-1] * inv[-1] % mod)
#
#
# def comb(n, r):
#     if n < r:
#         return 0
#     else:
#         return fac[n] * (finv[r] * finv[n - r] % mod) % mod

##############Find sum of product of subsets of size k in a array
# ar=[0,1,2,3]
# k=3
# n=len(ar)-1
# dp=[0]*(n+1)
# dp[0]=1
# for pos in range(1,n+1):
#     dp[pos]=0
#     l=max(1,k+pos-n-1)
#     for j in range(min(pos,k),l-1,-1):
#         dp[j]=dp[j]+ar[pos]*dp[j-1]
# print(dp[k])

def prefix_sum(ar):  # [1,2,3,4]->[1,3,6,10]
    return list(accumulate(ar))

def suffix_sum(ar):  # [1,2,3,4]->[10,9,7,4]
    return list(accumulate(ar[::-1]))[::-1]

def N():
    return int(inp())

# =========================================================================================
from collections import defaultdict

def numberOfSetBits(i):
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

def solve():
    n=N()
    s=inp()
    c_=0
    a=True
    b=True
    for c in s:
        if c=="<":
            a=False
        if c==">":
            b=False
    if a or b:
        print(n)
        return
    se=set()
    for i in range(n):
        if s[i]=="-":
            se.add(i)
            se.add((i+1)%n)
    print(len(se))

# solve()
testcase(int(inp()))


# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations  # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
# If the element is already present in the list,

# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect

# If the element is already present in the list,
# the right most position where element has to be inserted is returned

# ==============================================================================================
# fast I/O region

BUFSIZE = 8192
from sys import stderr

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):
    """Prints the values to a stream, or to sys.stdout by default."""
    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)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType

def iterative(f, stack=[]):
    print(stack)

    def wrapped_func(*args, **kwargs):
        if stack: return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
                continue
            stack.pop()
            if not stack: break
            to = stack[-1].send(to)
        return to

    return wrapped_func

#### END ITERATE RECURSION ####

# ===============================================================================================
# some shortcuts

mod = 1000000007

def inp(): return sys.stdin.readline().rstrip("\r\n")  # for fast input

def out(var): sys.stdout.write(str(var))  # for fast output, always take string

def lis(): return list(map(int, inp().split()))

def stringlis(): return list(map(str, inp().split()))

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

def strsep(): return map(str, inp().split())

def fsep(): return map(float, inp().split())

def nextline(): out("\n")  # as stdout.write always print sring.

def testcase(t):
    for p in range(t):
        solve()

def pow(x, y, p):
    res = 1  # Initialize result
    x = x % p  # Update x if it is more , than or equal to p
    if (x == 0):
        return 0
    while (y > 0):
        if ((y & 1) == 1):  # If y is odd, multiply, x with result
            res = (res * x) % p

        y = y >> 1  # y = y/2
        x = (x * x) % p
    return res

from functools import reduce

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)))

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

# discrete binary search
# minimise:
# def search():
#     l = 0
#     r = 10 ** 15
#
#     for i in range(200):
#         if isvalid(l):
#             return l
#         if l == r:
#             return l
#         m = (l + r) // 2
#         if isvalid(m) and not isvalid(m - 1):
#             return m
#         if isvalid(m):
#             r = m + 1
#         else:
#             l = m
#     return m

# maximise:
# def search():
#     l = 0
#     r = 10 ** 15
#
#     for i in range(200):
#         # print(l,r)
#         if isvalid(r):
#             return r
#         if l == r:
#             return l
#         m = (l + r) // 2
#         if isvalid(m) and not isvalid(m + 1):
#             return m
#         if isvalid(m):
#             l = m
#         else:
#             r = m - 1
#     return m

##to find factorial and ncr
# N=100000
# mod = 10**9 +7
# fac = [1, 1]
# finv = [1, 1]
# inv = [0, 1]
#
# for i in range(2, N + 1):
#     fac.append((fac[-1] * i) % mod)
#     inv.append(mod - (inv[mod % i] * (mod // i) % mod))
#     finv.append(finv[-1] * inv[-1] % mod)
#
#
# def comb(n, r):
#     if n < r:
#         return 0
#     else:
#         return fac[n] * (finv[r] * finv[n - r] % mod) % mod

##############Find sum of product of subsets of size k in a array
# ar=[0,1,2,3]
# k=3
# n=len(ar)-1
# dp=[0]*(n+1)
# dp[0]=1
# for pos in range(1,n+1):
#     dp[pos]=0
#     l=max(1,k+pos-n-1)
#     for j in range(min(pos,k),l-1,-1):
#         dp[j]=dp[j]+ar[pos]*dp[j-1]
# print(dp[k])

def prefix_sum(ar):  # [1,2,3,4]->[1,3,6,10]
    return list(accumulate(ar))

def suffix_sum(ar):  # [1,2,3,4]->[10,9,7,4]
    return list(accumulate(ar[::-1]))[::-1]

def N():
    return int(inp())

# =========================================================================================
from collections import defaultdict

def numberOfSetBits(i):
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

def solve():
    n = N()
    s = inp()
    c_ = 0
    if s.count("<")==0 or s.count(">")==0:
        print(n)
        return
    for i in range(n):
        if s[i] == "-" or s[(i - 1 + n) % n] == "-":
            c_ += 1
    print(c_)

# solve()
testcase(int(inp()))


def do():
    q = int(input())
    for _ in range(q):
        n = int(input())
        s = input()
        s = s + s + s
        l, c, r = n,n,n
        cnt = 0
        cntl = 0
        cntr = 0
        cntc = 0
        flag = False if s[n] == "-" else True
        if s[n] == "-":
            cntc += 1
        for i in range(n):
            if s[r] == "-":
                if s[r+1] == "-":
                    cntc += 1
                cntr += 1
            if s[r] == ">":
                cntr += 1
                flag = True
            if s[r] == "<":
                break
            r += 1
        flag = False if s[n] == "-" else True
        for i in range(n):
            if s[l] == "-":
                if s[l-1] == "-":
                    cntc += 1
                cntl += 1
            if s[l] == "<":
                cntl += 1
                flag = True
            if s[l] == ">":
                break
            l -= 1
        #print(cntc, cntl, cntr)
        if cntl >= n or cntr >= n:
            print(n)
        elif cntc == 0:
            print(0)
        else:
            print(min(cntc+1, n) )
do()


def do():
    q = int(input())
    for _ in range(q):

        n = int(input())
        s = input()
        if s.find("<") == -1:
            print(n)
            continue
        if s.find(">") == -1:
            print(n)
            continue
        if s[0] != "-" and s[-1] != "-":
            print(0)
            continue
        t = s + s + s
        r = l = n
        cnt = 1
        for i in range(n-1):
            r = r + 1
            if t[r] != "-":
                break
            cnt += 1
        for i in range(n-1):
            l = l - 1
            if t[l] != "-":
                break
            cnt += 1
        print(min(cnt + 1,n))
do()


def do():
    q = int(input())
    for _ in range(q):
        n = int(input())
        s = input()
        if s.find("<") == -1:
            print(n)
            continue
        if s.find(">") == -1:
            print(n)
            continue
        s = s[-1] + s + s[0]
        res = 0
        for i in range(1, n+1):
            if s[i-1] == "-" or s[i] == "-":
                res += 1
        print(res)

do()


def do():
    q = int(input())
    for _ in range(q):
        n = int(input())
        s = input()
        if s.find("<") == -1:
            print(n)
            continue
        if s.find(">") == -1:
            print(n)
            continue
        if s[0] != "-" and s[-1] != "-":
            print(0)
            continue
        s = s + s + s
        l =  r = n
        while s[l-1] == "-":
            l -= 1
        while s[r+1] == "-":
            r += 1
        cnt = 0
        #print(l,n,r)
        for i in range(l, r+1):
            if s[i] == "-":
                cnt += 1
        print(cnt + 1)
do()


def do():
    q = int(input())
    for _ in range(q):

        n = int(input())
        s = input()
        if s.find("<") == -1:
            print(n)
            continue
        if s.find(">") == -1:
            print(n)
            continue
        if s[0] != "-" and s[-1] != "-":
            print(0)
            continue
        t = s + s + s
        r = l = n
        cnt = 1
        for i in range(n-1):
            r = r + 1
            if t[r] != "-":
                break
            cnt += 1
        for i in range(n-1):
            l = l - 1
            if t[l] != "-":
                break
            cnt += 1
        print(cnt + 1)

do()


def do():
    q = int(input())
    for _ in range(q):
        n = int(input())
        s = input()
        if s.find("<") == -1:
            print(n)
            continue
        if s.find(">") == -1:
            print(n)
            continue
        s = s + s + s
        cnt = 0
        for i in range(n):
            x = n + i
            if s[n] == "-" or s[n-1] == "-":
                cnt += 1
        if s[0] == "-" and s[-1] == "-":
            cnt -= 1
        print(cnt)

do()


def do():
    q = int(input())
    for _ in range(q):
        n = int(input())
        s = input()
        s = s + s + s
        l, c, r = n,n,n
        cntl = 0
        cntr = 0
        cntc = 0

        if s[n] == "-":
            cntc += 1

        for i in range(n):
            r += 1
            if s[r] == "-":
                if s[r-1] == "-":
                    cntc += 1
                cntr += 1
            if s[r] == ">":
                cntr += 1
            if s[r] == "<":
                break

        for i in range(n):
            l -= 1
            if s[l] == "-":
                if s[l+1] == "-":
                    cntc += 1
                cntl += 1
            if s[l] == "<":
                cntl += 1
            if s[l] == ">":
                break

        #print(cntc, cntl, cntr)
        #print(s)
        if cntl >= n or cntr >= n:
            print(n)
        elif cntc == 0:
            print(0)
        else:
            print(min(cntc+1, n) )
do()


def do():
    q = int(input())
    for _ in range(q):
        n = int(input())
        s = input()
        s = s + s + s
        l, c, r = n,n,n
        cnt = 0
        cntl = 0
        cntr = 0
        cntc = 0

        flag = False
        for i in range(n):
            if s[l] == "-" and flag is False:
                if flag is False:
                    cntc += 1
                cntl += 1
            if s[l] == ">":
                cntl += 1
                flag = True
            if s[l] == "<":
                break
            l += 1
        flag = False
        for i in range(n):
            if s[r] == "-":
                if flag is False:
                    cntc += 1
                cntr += 1
            if s[r] == "<":
                cntr += 1
                flag = True
            if s[l] == ">":
                break
            r -= 1
        if cntl >= n or cntr >= n:
            print(n)
        else:
            print(cntc)
do()


def do():
    q = int(input())
    for _ in range(q):
        n = int(input())
        s = input()
        if s.find("<") == -1:
            print(n)
            continue
        if s.find(">") == -1:
            print(n)
            continue
        if s[0] != "-":
            print(0)
            continue
        t = s + s + s
        r = l = n
        cnt = 1
        for i in range(n-1):
            r = r + 1
            if t[r] != "-":
                break
            cnt += 1
        for i in range(n-1):
            l = l - 1
            if t[l] != "-":
                break
            cnt += 1
        print(cnt + 1)

do()


def do():
    q = int(input())
    for _ in range(q):
        n = int(input())
        s = input()
        s = s + s + s
        l, c, r = n,n,n
        cnt = 0
        cntl = 0
        cntr = 0
        cntc = 0

        flag = False if s[n] == "-" else True
        for i in range(n):
            if s[r] == "-":
                if flag is False:
                    cntc += 1
                cntr += 1
            if s[r] == ">":
                cntr += 1
                flag = True
            if s[r] == "<":
                break
            r += 1
        flag = False if s[n] == "-" else True
        for i in range(n):
            if s[l] == "-":
                if flag is False:
                    cntc += 1
                cntl += 1
            if s[l] == "<":
                cntl += 1
                flag = True
            if s[l] == ">":
                break
            l -= 1
        #print(cntc, cntl, cntr)
        if cntl >= n or cntr >= n:
            print(n)
        else:
            print(min(cntc, n) )
do()


def do():
    q = int(input())
    for _ in range(q):
        n = int(input())
        s = input()
        if s.find("<") == -1:
            print(n)
            continue
        if s.find(">") == -1:
            print(n)
            continue
        s = s + s + s
        cnt = 0
        for i in range(n-1):
            x = n + i
            if s[n] == "-" or s[n-1] == "-":
                cnt += 1
        print(cnt)

do()


for __ in range(int(input())):
    n = int(input())
    ar = list(input())
    ans = set()
    kek = set()
    flag = False
    for i in range(n):
        if ar[i] == '-':
            ans.add(i)
            ans.add((i + 1) % n)
        elif ar[i] == '>':
            kek.add(i % n)
        else:
            flag = True
    if flag:
        print(len(ans))
    else:
        ans = ans.union(kek)
        print(len(ans))


for __ in range(int(input())):
    n = int(input())
    ar = list(input())
    ans = set()
    kek1 = set()
    kek2 = set()
    flag1 = False
    flag2 = False
    for i in range(n):
        if ar[i] == '-':
            ans.add(i)
            ans.add((i + 1) % n)
        elif ar[i] == '>':
            kek1.add(i % n)
            flag2 = True
        else:
            kek2.add(i % n)
            flag1 = True
    if flag1 and flag2:
        print(len(ans))
    elif flag2 is False:
        ans = ans.union(kek2)
        print(len(ans))
    else:
        ans = ans.union(kek1)
        print(len(ans))


for __ in range(int(input())):
    n = int(input())
    ar = list(input())
    ans = set()
    kek = set()
    flag = False
    for i in range(n):
        if ar[i] == '-':
            ans.add(i)
            ans.add((i + 1) % n)
        elif ar[i] == '>':
            kek.add((i + 1) % n)
        else:
            flag = True
    if flag:
        print(len(ans))
    else:
        ans = ans.union(kek)
        print(len(ans))


for _ in range(int(input())):

    n = int(input())
    s = input()
    l = len(s)
    ans = l

    ar = [0]*l
    a,b,c = 0,0,0
    x = 0

    for i in range(l):

        if s[i] == '>':
            a+=1
        elif s[i] == '<':
            b+=1
        else:
            c+=1
    #print(a,b,c)
    if a == l or b== l or c ==l:
        print(l)
    elif c == 0 and a*b != 0:
        print(0)

    elif c!= 0 and a == 0 and  b != 0:
        print(l)
    elif c!= 0 and a != 0 and b == 0:
        print(l)
    #elif c!= 0 and b!= 0 and a!= 0:
    else:
        for i in range(0,l-1,2):
            if s[i] == '-' and s[i+1] != '-':
                x +=2

            elif s[i] == '-' and s[i+1] == '-':
                x+=1

        if s[-1] == '-':
            x+=1

        print(x)
    #else:
        #print(0)


for _ in range(int(input())):

    n = int(input())
    s = input()
    l = len(s)
    ans = l

    ar = [0]*l
    a,b,c = 0,0,0
    x = 0

    for i in range(l):

        if s[i] == '>':
            a+=1
        elif s[i] == '<':
            b+=1
        else:
            c+=1
    #print(a,b,c)
    if a == l or b== l or c ==l:
        print(l)
    elif c == 0 and a*b != 0:
        print(0)

    elif c!= 0 and a == 0 and  b != 0:
        print(l)
    elif c!= 0 and a != 0 and b == 0:
        print(l)
    #elif c!= 0 and b!= 0 and a!= 0:
    else:
        for i in range(l-1):
            if s[i] == '-' and s[i+1] != '-':
                x +=2

            elif s[i] == '-' and s[i+1] == '-':
                x+=1

        if s[-1] == '-':
            x+=1

        print(x)
    #else:
        #print(0)


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const nMax = 1e5;
char ss[nMax];
int temp[nMax];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0;i < n;i++){
        scanf("%d",&temp[i]);
    }
    scanf("%s",ss);
    int sum = 0;
    int sum1 = 0;
    int flag = 0;
    for(int i = n-1;i >= 0;i--){
        if( ss[i] != '0' ){
            flag = i;
            break;
        }
    }
    for(int i = 0;i <= flag;i++){
        sum+=temp[i];
        if( ss[temp-i] == '0' )
            sum1+=temp[i];
    }
    if( sum - temp[flag] > sum - sum1 )
        printf("%d\n",sum-temp[flag]);
    else
        printf("%d\n",sum-sum1);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const nMax = 1e5;
char ss[nMax];
int temp[nMax];
int main()
{
    int n;
    int sum[nMax];
    scanf("%d",&n);
    for(int i = 0;i < n;i++){
        scanf("%d",&temp[i]);
    }
    scanf("%s",ss);
    memset(sum,0,sizeof(sum));
    int sum1 = 0;
    int flag = 0;
    for(int i = n-1;i >= 0;i--){
        if( ss[i] != '0' ){
            flag = i;
            break;
        }
    }
    for(int i = 0;i <= flag;i++){
        if( i != 0 )
            sum[i] = temp[i] + sum[i-1];
        else
            sum[i] = temp[i];
        if( ss[i] == '0' )
            sum1+=temp[i];
    }
    int ans = max(sum[flag-1],sum[flag]-sum1);
    int fuck = 0;
    for(int i = flag-1;i > 0;i--)
        if( ss[i] == '1' && ss[i-1] != '0' ){
            fuck = sum[i-1]+temp[flag];
            ans = max(fuck,ans);
        }
    printf("%d\n",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const nMax = 1e5;
char ss[nMax];
int temp[nMax];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0;i < n;i++){
        scanf("%d",&temp[i]);
    }
    scanf("%s",ss);
    int sum = 0;
    int sum1 = 0;
    int flag = 0;
    for(int i = n-1;i >= 0;i--){
        if( ss[i] != '0' ){
            flag = i;
            break;
        }
    }
    for(int i = 0;i <= flag;i++){
        sum+=temp[i];
        if( ss[i] == '0' )
            sum1+=temp[i];
    }
    if( sum - temp[flag] > sum - sum1 )
        printf("%d\n",sum-temp[flag]);
    else
        printf("%d\n",sum-sum1);
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>

using namespace std;
const int MOD = 1000000007; // check!!!
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }

ll r[ten(5) + 10],l[ten(5) + 10];

int main(){
	int n; cin>>n;
	vector<int> a(n);
	FOR(i,n) cin>>a[i];
	string s; cin>>s;
	reverse(s.begin(),s.end());

	FOR(i,n){
		if(s[i] == '0'){
			r[i+1] = max(r[i],l[i] + a[i]);
		} else {
			l[i+1] = max(l[i],r[i]);
			r[i+1] = max(r[i],l[i] + a[i]);
		}
	}

	cout << l[n] << endl;

	return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>

using namespace std;
const int MOD = 1000000007; // check!!!
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }

ll r[ten(5) + 10],l[ten(5) + 10];

int main(){
	int n; cin>>n;
	vector<int> a(n);
	FOR(i,n) cin>>a[i];
	string s; cin>>s;

	FOR(i,n){
		if(s[i] == '0'){
			l[i+1] = l[i];
			r[i+1] = max(r[i],l[i] + a[i]);
		} else {
			l[i+1] = max(l[i] + a[i],r[i]);
			r[i+1] = max(r[i],l[i] + a[i]);
		}
	}

	cout << l[n] << endl;

	return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>

using namespace std;
const int MOD = 1000000007; // check!!!
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }

ll r[ten(5) + 10],l[ten(5) + 10];

int main(){
	int n; cin>>n;
	vector<int> a(n);
	FOR(i,n) cin>>a[i];
	string s; cin>>s;

	FOR(i,n){
		if(s[i] == '0'){
			l[i+1] = l[i];
		} else {
			l[i+1] = max(l[i] + a[i],r[i]);
		}
		r[i+1] = r[i] + a[i];
	}

	cout << l[n] << endl;

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
using namespace std;

    int n;
    int a[100000];
    string m;

int sum[100001];

int rec(int id) {
    if(id==n) return 0;
    if(m[id]=='0') {
        return rec(id+1);
    }
    if(m[id]=='1') {
        int cand = sum[id+1];
        int cand2 = a[id] + rec(id+1);
        return max(cand,cand2);
    }
}

int main() {
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[n-1-i];
    sum[n-1]=a[n-1];
    sum[n]=0;
    for(int i=n-2;i>=0;i--) {
        sum[i]=a[i]+sum[i+1];
    }
    cin>>m;
    reverse(m.begin(), m.end());
    cout<<rec(0)<<"\n";
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <queue>

using namespace std;

map<string,bool> dict;

vector<pair<int,int> > adjlist [103]; // indx, color
bool vis[105];
set<int> color_set;

void dfs  (int s, int color, int d){
    if(s == d)
        color_set.insert(color);

    vis[s] = true;

    for(int i=0;i<(int)adjlist[s].size();++i){
        pair<int,int> p = adjlist[s][i];
        if(p.second == color && !vis [p.first])
            dfs(p.first,p.second,d);

    }
}

int main (){

    //freopen("in.txt","r",stdin);

    int n,m,u,v,c,q;

    cin>>n>>m;

    while(m--){
        cin>>u>>v>>c;
        u--;
        v--;
        adjlist[u].push_back(make_pair(v,c));
        adjlist[v].push_back(make_pair(u,c));
    }

    cin>>q;
    while(q--){
        cin>>u>>v;
        --u;
        --v;
        memset(vis,0,sizeof vis);
        color_set.clear();
        vis[u] = true ;
        for(int i=0;i<(int)adjlist[u].size();++i){
            memset(vis,0,sizeof vis);
            dfs(adjlist[u][i].first,adjlist[u][i].second,v);
        }
        cout<<color_set.size()<<endl;
    }

    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <queue>

using namespace std;

int dp [100005][2];
int n, list [100004];
string s;

int solve (int cur,int change){
    if(cur == -1)
        return 0;

    if(dp[cur][change] != -1)
        return dp[cur][change];

    int ans=0, a=0;

    if(s[cur] == '1'){
        ans = max( list[cur] + solve(cur-1,change) , solve(cur-1,1) );
    }else{
        if(change == 1)
            a = list[cur]+solve(cur-1,change);
        ans  = max(a,solve(cur-1,change));
    }
    return dp[cur][change] = ans;
}
int main(){
    //freopen("in.txt","r",stdin);

    cin>>n;
    for(int i=0;i<n;++i)
        cin>>list[i];
    cin>>s;
    memset(dp,-1,sizeof dp);
    cout<<solve(n-1,0);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef pair<int,int> PII;

int a[100005];
int c[100005],dp[100005][2];

int gao(int i, int t){
    if(i<0) return 0;
    if(~dp[i][t]) return dp[i][t];
    if(t) return dp[i][t]=a[i]+gao(i-1,1);
    if(c[i]) return dp[i][t]=max(gao(i-1,1),gao(i-1,0)+a[i]);
    return dp[i][t]=gao(i-1,0);
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d" ,a+i);
    for(int i=0;i<n;i++) scanf("%1d",c+i);
    memset(dp,-1,sizeof(dp));
    printf("%d\n",gao(n-1,0));
}


#include <cstdio>
#include <vector>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &(a[i]));
  }
  vector<int> b(n);
  int c = getchar();
  while (c <= 32) c = getchar();
  for (int i = 0; i < n; i++) {
    b[i] = c - '0';
    c = getchar();
  }
  int s = 0;
  for (int i = 0; i < n; i++) s += a[i];
  int s2 = 0;
  int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    s -= a[i];
    if (b[i] == 0) continue;
    if (b[i] == 1) {
      if (s + s2 > ans) ans = s + s2;
    }
    s2 += a[i];
  }
  if (s + s2 > ans) ans = s + s2;
  printf("%d\n", ans);
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>

using namespace std;

typedef long long int64;

const int oo = 0x3f3f3f3f;

int N, Answer;
vector<int> Values;
string UpperBound;

void Solve() {
    vector<int> maxSum = vector<int>(N + 1, 0);
    for (int i = 1; i <= N; ++i)
        maxSum[i] = maxSum[i - 1] + max(0, Values[i - 1]);
    Answer = 0;
    for (int i = N - 1, sum = 0; i >= 0; --i) {
        if (UpperBound[i] == '1') {
            Answer = max(Answer, sum + maxSum[i]);
            sum += Values[i];
        }
        Answer = max(Answer, sum);
    }
}

void Read() {
    cin >> N;
    Values = vector<int>(N);
    for (int i = 0; i < N; ++i)
        cin >> Values[i];
    cin >> UpperBound;
}

void Print() {
    cout << Answer << "\n";
}

int main() {
    #ifndef ONLINE_JUDGE
        assert(freopen("c.in", "r", stdin));
        assert(freopen("c.out", "w", stdout));
    #endif
    Read();
    Solve();
    Print();
    return 0;
}


/*
 Author:   Harhro94 [Harutyunyan Hrayr]
 IDE:      Visual C++ 2012
*/
#pragma comment(linker, "/STACK:66777216")
#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <string>
#include <bitset>
#include <vector>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using namespace std;

typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

const int INF = 1000000007;
const int N = 100007;
int n, a[N], dp[N][2];
char st[N];

int main()
{
#ifdef harhro94
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
    //freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#endif

    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    reverse(a, a + n);
    scanf("%s", st);
    reverse(st, st + n);
    fill(dp[0], dp[0] + 2 * N, -INF);
    dp[0][1] = 0;
    for (int i = 0; i < n; ++i)
    {
        dp[i + 1][1] = dp[i][1] + (st[i] == '0' ? 0 : a[i]);
        dp[i + 1][0] = dp[i][0] + a[i];
        if (st[i] == '1') dp[i + 1][0] = max(dp[i + 1][0], dp[i][1]);
    }
    cout << max(dp[n][0], dp[n][1]) << endl;

#ifdef harhro94
    cerr << fixed << setprecision(3) << "\nExecution time = " << clock() / 1000.0 << "s\n";
#endif
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> m(n);
    for(ll i=0; i<n; ++i) {
        cin>>a[i];
    }
    ll sum=0;
    ll paras=0;
    ll pituus=0;
    vector<ll> st(n);
    vector<ll> at(n);
    for(ll i=0; i<n; ++i) {
        char qq;
        cin>>qq;
        m[i]=qq-48;
        if(m[i]) {
            sum+=a[i],pituus=i+1;
            if(!i) at[i]=a[i];
            else at[i]=at[i-1]+a[i];
        }
        else if (i) at[i]=at[i-1];
        if(!i) st[i]=a[i];
        else st[i]=st[i-1]+a[i];
    }
    paras=sum;
    sum=0;
    for(ll i=0; i<pituus; ++i) {
        ll uusi=at[pituus-1]-at[i];
        if(i && m[i]) uusi+=st[i-1];
        if(uusi>paras) paras=uusi;
    }
    if(sum>paras) paras=sum;
    cout<<paras<<'\n';

}


#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> m(n);
    for(ll i=0; i<n; ++i) {
        cin>>a[i];
    }
    ll sum=0;
    ll paras=0;
    ll pituus=0;
    for(ll i=0; i<n; ++i) {
        char qq;
        cin>>qq;
        m[i]=qq-48;
        if(m[i]) sum+=a[i],pituus=i+1;
    }
    paras=sum;
    sum=0;
    for(ll i=0; i<pituus-1; ++i) {
        sum+=a[i];
    }
    if(sum>paras) paras=sum;
    cout<<paras<<'\n';

}


#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> m(n);
    for(ll i=0; i<n; ++i) {
        cin>>a[i];
    }
    ll sum=0;
    ll paras=0;
    ll pituus=0;
    vector<ll> st(n);
    vector<ll> at(n);
    for(ll i=0; i<n; ++i) {
        char qq;
        cin>>qq;
        m[i]=qq-48;
        if(m[i]) {
            sum+=a[i],pituus=i+1;
            if(!i) at[i]=a[i];
            else at[i]=at[i-1]+a[i];
        }
        else if (i) at[i]=at[i-1];
        if(!i) st[i]=a[i];
        else st[i]=st[i-1]+a[i];
    }
    paras=sum;
    sum=0;
    for(ll i=0; i<pituus; ++i) {
        ll uusi=at[pituus-1]-at[i];
        if(i) uusi+=st[i-1];
        if(uusi>paras) paras=uusi;
    }
    if(sum>paras) paras=sum;
    cout<<paras<<'\n';

}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    string s;
    cin >> s;
    int totalSum = 0;
    int maxSum = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '1') {
            maxSum = max(maxSum + a[i], totalSum);
        }
        totalSum += a[i];
    }
    cout << maxSum << endl;

    return 0;

}


// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define patkan 9
#define tisic 47
#define soclose 10e-7
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define chocolate win
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):(x))
// mylittlepony
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    int N;
    cin >> N;
    vector<int> V(N);
    for(int i =0; i < N; i++) cin >> V[i];
    string M;
    cin >> M;
    vector<int> S(N+1,0);
    for(int i =0; i < N; i++) S[i+1] =S[i]+V[i];

    int ans =0, a =0;
    for(int i =N-1; i >= 0; i--) if(M[i] == '1') {
        ans =max(ans,a+S[i]);
        a +=V[i];}
    ans =max(ans,a);
    cout << ans << "\n";
    return 0;}

// look at my code
// my code is amazing


// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define patkan 9
#define tisic 47
#define soclose 10e-7
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define chocolate win
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):(x))
// mylittlepony
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    int N,a;
    cin >> N;
    vector<int> V(2*N);
    vector< vector<int> > pos(100);
    for(int i =0; i < 2*N; i++) {
        cin >> a;
        V[i] =a;
        pos[a].push_back(i);
        poc[a]++;}

    int ansA =0, ansB =0;
    vector<int> S(2*N);
    for(int i =0; i < 100; i++) if(poc[i] > 1) {
        ansA++, ansB++;
        S[pos[i][0]] =0;
        S[pos[i][1]] =1;}
    for(int i =0; i < 100; i++) if(poc[i] == 1) {
        if(ansA < ansB) {ansA++; S[pos[i][0]] =0;}
        else {ansB++; S[pos[i][0]] =1;}}
    cout << ansA*ansB << "\n";

    for(int i =0; i < 100; i++) for(int j =2; j < poc[i]; j++) {
        if(ansA < N) {ansA++; S[pos[i][j]] =0;}
        else {ansB++; S[pos[i][j]] =1;}}
    for(int i =0; i < 2*N; i++) cout << S[i]+1 << ((i == 2*N-1)?"\n":" ");
    return 0;}

// look at my code
// my code is amazing


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define _int64 long long

char s[110000];
int a[110000];

int main()
{
  int i,j,n,tot,sum,ans;
  scanf("%d",&n);
  tot=0;
  for (i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
    tot+=a[i];
  }
  scanf("%s",s);
  reverse(s,s+n);
  ans=0;
  sum=0;
  for (i=0;i<n;i++)
  {
    tot-=a[n-1-i];
    if (s[i]=='1')
    {
      //cout<<tot<<" "<<i<<endl;
      if (sum+tot>ans) ans=sum+tot;
      sum+=a[n-1-i];
    }
  }
  if (sum>ans) ans=sum;
  printf("%d\n",ans);
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <string>

int main(){

    long n; scanf("%ld\n", &n);
    std::vector<long> a(n,0);
    long ans(0), sum(0);
    for(long p = 0; p < n; p++){scanf("%ld", &a[p]); sum += a[p];}
    scanf("\n"); std::string x; getline(std::cin, x);

    for(long p = n - 1; p >= 0; p--){
        if(x[p] == '1'){ans = (ans > (sum - a[p])) ? ans : (sum - a[p]);}
        else{sum -= a[p];}
    }

    if(ans < sum){ans = sum;}

    printf("%ld\n", ans);

    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <string>

int main(){

    long n; scanf("%ld\n", &n);
    std::vector<long> a(n,0);
    long ans(0), sum(0);
    for(long p = 0; p < n; p++){scanf("%ld", &a[p]); sum += a[p];}
    scanf("\n"); std::string x; getline(std::cin, x);
    std::cout << x << std::endl;

    for(long p = n - 1; p >= 0; p--){
        printf("%ld  ==>%c<==\n", p,  x[p]);
        if(x[p] == '1'){ans = (ans > (sum - a[p])) ? ans : (sum - a[p]);}
        else{sum -= a[p];}
    }

    if(ans < sum){ans = sum;}

    printf("%ld\n", ans);

    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <string>

int main(){

    long n; scanf("%ld\n", &n);
    std::vector<long> a(n,0);
    long ans(0), sum(0);
    for(long p = 0; p < n; p++){scanf("%ld", &a[p]); sum += a[p];}
    scanf("\n"); std::string x; getline(std::cin, x);

    for(long p = n - 1; p >= 0; p--){
        if(x[p] == '1'){ans = (ans > (sum - a[p])) ? ans : (sum - a[p]);}
        else{sum -= a[p];}
    }

    printf("%ld\n", ans);

    return 0;
}


#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
	int i, n;
	string temp;
	long long sum = 0, max = 0;

	cin >> n;

	vector<int> as(n,0);
	vector<bool> ss(n,0);
	vector<int> sums(n,0);

	for (i = 0; i < n; ++i)
		cin >> as[i];
	for (i = 1; i < n; ++i)
		sums[i] = sums[i-1] + as[i-1];

	cin >> temp;
	for (i = n-1; i >= 0; --i) {
		if (temp[i] == '1') {
			max = sum + sums[i] > max ? sum + sums[i] : max;
			sum += as[i];
		}
	}

	sum = max > sum ? max : sum;

	cout << sum << endl;

	return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <cassert>
#include <numeric>
#include <sstream>
#include <limits>
using namespace std;

#define REQUIRE(cond, message) \
    do { \
        if (!(cond)) { \
            std::cerr << message << std::endl; \
            assert(false); \
        } \
    } while (false)

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define forv(i, v) forn(i, (v).size())
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<string> vs;
typedef long double ld;

template<typename T>
inline int popcount(T t) {
    if (std::numeric_limits<T>::digits <=
                            std::numeric_limits<unsigned int>::digits) {
        return __builtin_popcount(t);
    } else {
        return __builtin_popcountll(t);
    }
}

const ld EPS = 1e-8;
const ld PI = acosl(0.0) * 2;

void solve()
{
    int n; cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];
    string m;
    cin >> m;
    vi s(a);
    forn(i, n) if (i) s[i] += s[i - 1];
    int cur = 0;
    int ans = 0;
    for (int i = static_cast<int>(m.size()) - 1; i >= 0; --i) {
        if (m[i] == '0') continue;
        ans = max(ans, ((i) ? s[i - 1]:0) + cur);
        cur += a[i];
    }
    ans = max(ans, cur);
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


#include <iostream>

int Best[100005], A[100005], All[100005], N;
using namespace std;
string S;

int main()
{
    cin >> N;

    for(int i = 0; i < N; i++)
        cin >> A[i];

    cin >> S;

    All[0] = A[0];
    Best[0] = S[0] == '1' ? A[0] : 0;

    for(int i = 1; i < N; i++)
    {
        if(S[i] == '1')
            Best[i] = max(Best[i-1] + A[i], All[i-1]);
        else
            Best[i] = Best[i-1];

        All[i] = All[i-1] + A[i];
    }

    cout << Best[N-1];
}


#include <iostream>

int A[100005],B,E,N;
using namespace std;
string S;

int main()
{
    cin>>N;
    for(int i=0;i<N;i++) cin>>A[i];
    cin>>S;
    E=A[0],B=S[0]=='1'?A[0]:0;
    for(int i=1;i<N;i++)
    {
        if(S[i]=='1') B=max(B+A[i],E);
        E+=A[i];
    }
    cout<<B;
}


//created by Yash Sadhwani
//sadhwaniyash6
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include<deque>
#include<map>
#include<set>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<stack>
#include<functional>
using namespace std;
#define ll long long
#define si(x) scanf("%d",&x)
#define sc(x) scanf("%c",&x)
#define vl vector<ll>
#define vi vector<int>
#define vvl vector< vl >
#define vvi vector< vi >
#define pb push_back
#define mod 1000000009
#define mem(x,y) memset(x,y,sizeof(x))
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define max_int_value 2147483647
#define max_long_value 9223372036854775807
//qsort(ww,cc,sizeof(tp),compare);
/*int compare(const void *a,const void *b){
    ll y=((((tp*)a)->w)-(((tp*)b)->w));
    if(y>0)return 1;
    else if(y==0)return 0;
    else return -1;
}
bool way(ii x,ii y){
    return x.first<y.first or x.first==y.first and x.second<y.second;
}
*/

#define MAXN 100010
#define ls (node<<1)
#define rs ((node<<1)+1)

int N;
int arr[MAXN];
char str[MAXN*10];
int len;
int sums[MAXN];

inline void ReadInput(void){
    si(N);
    int prev=0;
    for(int i=0;i<N;i++){
        cin>>arr[i];
        sums[i]=prev+arr[i];
        prev=sums[i];
    }
    cin>>str;
    len=strlen(str);
}

inline void solve(void){
    int prevMax=0,ans=0;
    int k=min(len,N);
    for(int i=0;i<k;i++){
        if(str[i]=='1'){
            ans=max(prevMax+arr[i],sums[i-1]);
            prevMax=ans;
        }
    }
    if(len>N)ans=sums[N-1];
    cout<<ans<<endl;
}

inline void Refresh(void){

}

int main()
{
    //ios_base::sync_with_stdio(false);
    ReadInput();
    solve();
    return 0;
}


#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i < n;i++) cin >> a[i];

    string s;
    cin >> s;

    int len = s.length();
    int res = 0, sum_l = 0;
    for(int i = 0;i < len;i++){
        if(s[i] == '1') {
            res += a[i];
            res = max(res, sum_l);
        }
        sum_l += a[i];
    }

    cout << res << endl;

    return 0;
}


#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i < n;i++) cin >> a[i];

    string s;
    cin >> s;

    int res = 0, sum = 0;
    for(int i = 0;i < n;i++){
        if(s[i] == '1') {
            res += a[i];
            res = max(res, sum);
        }
        sum += a[i];
    }

    cout << res << endl;

    return 0;
}


#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i < n;i++) cin >> a[i];

    string s;
    cin >> s;

    int res = 0, sum = 0;
    for(int i = 0;i < n;i++){
        if(s[i] == '1') {
            res += a[i];
            res = max(res, sum);
        }
        sum += a[i];
    }

    cout << res << endl;

    return 0;
}


#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i < n;i++) cin >> a[i];

    string s;
    cin >> s;

    int len = s.length();
    int res = 0, sum_l = 0;
    for(int i = 0;i < len;i++){
        if(s[i] == '1') {
            res += a[i];
            max(res, sum_l);
        }
        sum_l += a[i];
    }

    cout << res << endl;

    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

#define fi first
#define se second

typedef long long ll;

const int N = 1111111;
const int INF = 1000000000, mod = 1000000007;
const ll LLINF = 1000000000000000000ll;

int a[N];
char s[N];

int suff[N];
int is[N];

int main () {

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int ans = 0;

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }

    gets(s);
    gets(s);

    reverse(s, s + n);
    reverse(a, a + n);

    for (int i = n - 1; i >= 0; --i) {
        suff[i] = a[i];
        suff[i] += suff[i + 1];
    }

    is[n] = 1;
    for (int i = n - 1; i >= 0; --i) {
        is[i] = is[i + 1] & (s[i] - '0');
    }

    int sum = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            ans = max(ans, sum + suff[i + 1] + a[i] * is[i]);
            sum += a[i];
        }
    }

    printf("%d\n", ans);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

#define fi first
#define se second

typedef long long ll;

const int N = 1111111;
const int INF = 1000000000, mod = 1000000007;
const ll LLINF = 1000000000000000000ll;

int a[N];
char s[N];

int suff[N];

int main () {

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int ans = 0;

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }

    gets(s);
    gets(s);

    reverse(s, s + n);
    reverse(a, a + n);

    for (int i = n - 1; i >= 0; --i) {
        suff[i] = a[i];
        suff[i] += suff[i + 1];
    }

    int sum = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            ans = max(ans, sum + suff[i + 1] + a[i] * (*min_element(s + i, s + n) == '1'));
            sum += a[i];
        }
    }

    printf("%d\n", ans);
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
#include <ctime>

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <stack>
using namespace std;
typedef vector<int> vi;
typedef map<int,int> mii;
typedef long long ll;
template <class T> void checkmax(T &t, T x){if (x > t) t = x;}
template <class T> void checkmin(T &t, T x){if (x < t) t = x;}
template <class T> void _checkmax(T &t, T x){if (t == -1 || x > t) t = x;}
template <class T> void _checkmin(T &t, T x){if (t == -1 || x < t) t = x;}
#define INF (INT_MAX/10)
#define SQR(x) ((x)*(x))
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repf(i, a, b) for (int i=(a); i<=(b); ++i)
#define repd(i, a, b) for (int i=(a); i>=(b); --i)
#define iter(v) __typeof((v).begin())
#define foreach(it, v) for (iter(v) it = (v).begin(); it != (v).end(); it++)
#define clr(ar,val) memset(ar, val, sizeof(ar))
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) a.begin(), a.end()
#define mid(x, y) ((x+y)/2)
#define vp vector<P>
#define itr iterator

#define N 100000

int i,j,k,m,n,l;
char s[N+10];
int a[N+10], sum[N+10];

int main(){
	while (~scanf("%d", &n)){
		rep(i, n){
		   	scanf("%d", &a[i]);
			if (i) sum[i]=sum[i-1]+a[i];
			else sum[i]=a[i];
		}

		scanf("%s", s);
		int pre=0, ret=0;
		repd(i, n-1, 0){
			if (s[i]=='1'){
			   	checkmax(ret, pre+((i==0)?0:(sum[i-1])));
				pre+=a[i];
			}
		}
		checkmax(ret, pre);
		printf("%d\n", ret);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>

using namespace std;

#define ll long long

string s,t="";
int n,i,a[100001],res1=0,res2=0;
ll res=0,ans=0,sum[1000001]={0};

int main()
{
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    reverse(a,a+n);
    cin>>s;
    sum[n]=0;
    for(i=n-1;i>=0;i--)
        sum[i]=sum[i+1]+a[i];
    for(i=0;i<n;i++)
        t=t+s[n-i-1];
    for(i=0;i<n;i++)
    {
        if(t[i]=='1')ans=max(ans,res+sum[i+1]);
        if(t[i]=='1')res+=a[i];
    }
    ans=max(ans,res);
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define TR(i,v)         for(__typeof((v).begin())i=(v).begin();i!=(v).end();++i)
#define DEBUG(x)        cout << #x << " = " << x << endl;
#define SIZE(p)         (int)(p).size()
#define MP(a, b)        make_pair((a), (b))
#define ALL(p)          (p).begin(), (p).end()
#define rep(i, n)       for(int (i)=0; (i)<(int)(n); ++(i))
#define REP(i, a, n)    for(int (i)=(a); (i)<(int)(n); ++(i))
#define FOR(i, a, b)    for(int (i)=(int)(a); (i)<=(int)(b); ++(i))
#define FORD(i, b, a)   for(int (i)=(int)(b); (i)>=(int)(a); --(i))
#define CLR(x, y)       memset((x), (y), sizeof((x)))
typedef long long LL;
typedef pair<int, int> pii;

int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
    freopen("A.in", "r", stdin);
    // freopen("out", "w", stdout);
#endif
    // ios::sync_with_stdio(false);     cin.tie(0);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define TR(i,v)         for(__typeof((v).begin())i=(v).begin();i!=(v).end();++i)
#define DEBUG(x)        cout << #x << " = " << x << endl;
#define SIZE(p)         (int)(p).size()
#define MP(a, b)        make_pair((a), (b))
#define ALL(p)          (p).begin(), (p).end()
#define rep(i, n)       for(int (i)=0; (i)<(int)(n); ++(i))
#define REP(i, a, n)    for(int (i)=(a); (i)<(int)(n); ++(i))
#define FOR(i, a, b)    for(int (i)=(int)(a); (i)<=(int)(b); ++(i))
#define FORD(i, b, a)   for(int (i)=(int)(b); (i)>=(int)(a); --(i))
#define CLR(x, y)       memset((x), (y), sizeof((x)))
typedef long long LL;
typedef pair<int, int> pii;

int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
    freopen("C.in", "r", stdin);
    // freopen("out", "w", stdout);
#endif
    // ios::sync_with_stdio(false);     cin.tie(0);
    int n;  scanf("%d",&n);
    static int A[100005],pa[100005];
    FOR(i,1,n)  scanf("%d",A+i),pa[i]=A[i]+pa[i-1];
    static char s[100005];
    scanf("%s",s+1);
    int res=0,sum=0;
    FORD(i,n,0) {
        if(s[i]=='0')
            continue;
        res=max(res,sum+pa[i-1]);
        sum+=A[i];
    }
    printf("%d\n",res);
    return 0;
}


#include <bits/stdc++.h>
#define endl "\n"
#define FOR(x, y, z) for (int x = (y); x < (z); ++x)
#define FORR(x, y, z) for (int x = (y); x > (z); --x)
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define GET(a, n) for (int i = 0; i < n; ++i) cin >> a[i];
#define GETM(a, n, m) for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j];
#define PRINTM(a, n, m) for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) cout << a[i][j] << " ";  cout << endl; };
#define PRINT(a, n) for (int i = 0; i < n; ++i) cout << a[i] << " ";
#define LL long long
#define ULL unsigned long long
#define VI vector <int>
#define VVI vector <vector<int>>
#define PII pair <int, int>
#define GETSUM(sum, n) sum = 0; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; sum += tmp; }
#define SUM(a, n, sum) sum = 0; for (int i = 0; i < n; ++i) { sum += a[i]; }
#define IT(a) a.begin(), a.end()
using namespace std;
template <class T> typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; FOR(i, 0, n) sum += v[i]; return sum; }
struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio;

int main()
{
    int n;
    cin >> n;
    VI v(n);
    GET(v, n);
    VI s(n);
    s[0] = v[0];
    FOR (i, 1, n) {
        s[i] = s[i - 1] + v[i];
    }
    string str;
    cin >> str;
    int sum = 0;
    FOR (i, 0, str.size()) {
        if (str[i] == '1') {
            sum += v[i];
        }
    }
    int tmp = 0;
    FORR (i, str.size() - 1, 0) {
        if (str[i] == '1') {
            sum = max(sum, tmp + s[i - 1]);
            tmp += v[i];
        }
    }
    cout << sum;
}


#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

#define M 100500
int a[M],sum[M];
char s[M];
int main()
{
    int n, i;
    scanf("%d", &n);
    for(i = 0;i < n; i++) {
        cin>>a[i];
        sum[i] = i ? sum[i-1] + a[i] : a[i];
    }
    scanf("%s", s);
    ll ans = 0, all = 0;
    for(i = n - 1; i >= 0; i--){
        if(s[i] != '0'){
            ans=max(ans, all + (i ? sum[i-1] : 0));
            all += a[i];
        }
    }
    ans = max(ans, all);
    printf("%I64d\n", ans);
    return 0;
}


#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

#define M 100500
int a[M],sum[M];
char s[M];
int main()
{
    int n, i;
    cin>>n;
    for(i = 0;i < n; i++) {
        cin>>a[i];
        sum[i] = i ? sum[i-1] + a[i] : a[i];
    }
    cin>>s;
    ll ans = 0, all = 0;
    for(i = n - 1; i >= 0; i--){
        if(s[i] != '0'){
            ans=max(ans, all + (i ? sum[i-1] : 0));
            all += a[i];
        }
    }
    ans = max(ans, all);
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;
int n;

int main ()
{
    scanf ("%d", &n);
    vector <int> a(n + 1);
    char s[1000001];
    int sum = 0, ans = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    scanf ("%s", s);
    for (int i = n - 1; i >= 0; i--)
    {
        if (s[i] == '0')
            sum -= a[i];
        else
            ans = max(ans, sum -a[i]);
    }
    ans = max (ans, sum);
    printf ("%d", ans);
    return 0;
}


#include <iostream>
#include <algorithm>

unsigned int elems[100000];

int main()
{
	unsigned int candA = 0;
	unsigned int candB = 0;

	unsigned int lastOne = 0;

	unsigned int n;
	std::cin >> n;

	for(unsigned int i = 0; i < n; i++)
	{
		std::cin >> elems[i];
	}

	for(unsigned int i = 0; i < n; i++)
	{
		char c;

		std::cin >> c;

		if(c == '1')
		{
			candA += elems[i];
			lastOne = i;
		}
	}

	for(unsigned int i = 0; i < lastOne; i++)
	{
		candB += elems[i];
	}

	std::cout << std::max(candA, candB) << std::endl;

	return 0;
}


#include <iostream>
#include <algorithm>

unsigned int elems[100000];

int main()
{
	unsigned int candMax = 0;

	unsigned int n;
	std::cin >> n;

	for(unsigned int i = 0; i < n; i++)
	{
		std::cin >> elems[i];
	}

	unsigned int sum = 0;

	for(unsigned int i = 0; i < n; i++)
	{
		char c;

		std::cin >> c;

		if(c == '1')
		{
			unsigned int a = candMax + elems[i];
			unsigned int b = sum;

			candMax = std::max(a, b);
		}

		sum += elems[i];
	}

	std::cout << candMax << std::endl;

	return 0;
}


/* **********************************************
Author      : JayYe
Created Time: 2013/10/10 23:44:43
File Name   : Orz.cpp
*********************************************** */

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef __int64 ll;

const int maxn = 100000 + 10;
ll a[maxn], sum[maxn];

char s[maxn];
int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1;i <= n; i++)
        scanf("%I64d", &a[i]);
    scanf("%s", s+1);
    for(int i = 1;i <= n; i++)
        sum[i] = sum[i-1] + a[i];
    int len = strlen(s+1);
    while(len > 0 && s[len] == '0')
        len--;
    if(len == 0)
        return puts("0");
    ll ans = sum[len-1];
    ll tmp = 0;
    for(int i = len;i >= 1; i--) {
        if(s[i] == '1') {
            ans = max(tmp + sum[i-1], ans);
            tmp += a[i];
        }
    }
    ans = max(ans, tmp);
    printf("%I64d\n", ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstring>
#include <fstream>
#include <ctime>

#define LL long long
#define ULL unsigned long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FO(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FOD(i,a,b) for(int i=a;i>b;i--)
#define FORV(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end(); i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define debug cout << "YES" << endl

using namespace std;

typedef pair<int,int>II;
typedef pair<int,II>PII;
template<class T> T gcd(T a, T b) {T r; while(b!=0) {r=a%b;a=b;b=r;} return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }

const double PI = 2*acos(0.0);
const double eps = 1e-9;
const int infi = 1e9;
const LL Linfi = (LL) 9e18;
const LL MOD = 1000000007;
#define maxn 100005

int n;
int a[maxn], sum[maxn];
string s;

void solve(){
	sum[0] = 0;
	FOR(i,1,n) sum[i] = sum[i-1] + a[i];
	int cur = 0, res = 0;
	FORD(i,s.size()-1,1){
		if(s[i] == '1'){
			res = max(res, cur + sum[i-1]);
			cur += a[i];
		}
	}
	res = max(res, cur);
	cout << res << endl;
}

int main(){
    ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
    freopen("test.in","r",stdin);
    //freopen("test.out","w",stdout);
    #endif
	cin >> n;
	FOR(i,1,n) cin >> a[i]; cin.ignore(1);
	cin >> s; s = '0' + s;
	solve();

    return 0;
}


#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    long long ans = 0,prev_sum=0;
    cin>>n;
    vector<int> a(n);
    vector<int> pref(n);
    for(int i =0; i<n; ++i)
        cin>>a[i];
    pref[0] = a[0];
    for(int i = 1; i<n; ++i)
        pref[i]=a[i] + pref[i-1];
    string m;
    cin>>m;
    for(int i = 0; i<n; ++i)
        if(m[i]=='1') ans+=a[i]; // M
    for(int i = n-1; i>=0; --i)
        if (m[i] == '1')
            {ans = max(ans, (i > 0 ? pref[i - 1] : 0) + prev_sum); prev_sum += a[i];} // GPS
    cout<<ans;
}


#include <cstdio>
#include <algorithm>
using namespace std;

int main() {

	int n;
	scanf("%d", &n);

	int a[100000];
	for(int i = 0; i < n; ++i)
		scanf("%d", &a[i]);

	char s[100001];
	scanf("%s", s);

	int ans = 0;
	for(int i = 0; i < n; ++i)
		if('1' == s[i])
			ans += a[i];

	int partialAns = ans;

	for(int i = 0; i < n; ++i)
		if('1' == s[i]){
			partialAns -= a[i];
			s[i] = '0';
			for(int j = i-1; j >= 0 && '0' == s[j]; --j)
				partialAns += a[j],
				s[j] = '1';
			ans = max(ans, partialAns);
		}

	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int sz = 1e5+111;
int N;
int a[sz], sum[sz];
string binary;

int main()
{
  cin >> N;
  for(int i = 0; i < (int)N; ++i) {
    cin >> a[i];
  }
  cin >> binary;
  reverse(a, a+N);
  reverse(binary.begin(), binary.end());

  sum[N-1] = a[N-1];
  for(int i = (int)N-2; i >= (int)0; --i) {
    sum[i] = a[i] + sum[i+1];
  }

  long long ret = 0, curSum = 0;

  for(int i = 0; i < (int)N; ++i) {
    if(binary[i] == '1') {
      long long tmpSum = curSum + sum[i+1];
      ret = max(ret, tmpSum);
      curSum += a[i];
    }
    ret = max(curSum, ret);
  }
  cout << ret << "\n";

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REV(i,b,a) for(int i=(a);i>=(b);i--)
#define mp make_pair
#define pb push_back
#define oo (1<<30)
#define sz(v) (int)v.size()
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define mem(s,v) memset(s,v,sizeof(s))
#define ppc(x) __builtin_popcount((x))
#define iter(it,s) for(__typeof(s.begin())it = s.begin();it!=s.end();it++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

int dx[] = { 0, 0, 1, -1 };
int dy[] = { 1, -1, 0, 0 };

const int len = 100005;
ll cum[len];
int nxt[len], n;
string s;

int rec(int idx) {
  if (idx == n)
    return 0;
  int res = 0;
  res = max(rec(nxt[idx]) + cum[idx] - cum[idx + 1], cum[idx + 1]);
  return res;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("test.in", "rt", stdin);
//	freopen("o.txt", "wt", stdout);
#endif
  ios::sync_with_stdio(false);
  cin >> n;
  FOR (i , 1 , n + 1) {
    int x;
    cin >> x;
    cum[i] = cum[i - 1] + x;
    nxt[i - 1] = n;
  }
  cin >> s;
  reverse(all(s));
  reverse(cum, cum + n + 1);
  int id = -1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      if (id != -1)
        nxt[i] = id;
      id = i;
    }
  }
  if (id == -1) {
    cout << 0;
    return 0;
  }
  int res = rec(id);
  cout << res << endl;
  return 0;
}