Lira is now very keen on compiler development. :) 
She knows that one of the most important components of a compiler, is its parser.
A parser is, in simple terms, a software component that processes text, and checks it's semantic correctness, or, if you prefer, if the text is properly built.
As an example, in declaring and initializing an integer, in C/C++, you can't do something like:
int = x ;4
as the semantics of such statement is incorrect, as we all know that the datatype must precede an identifier and only afterwards should come the equal sign and the initialization value, so, the corrected statement should be:
int x = 4;
Today, Lira is concerned with an abstract instruction which is composed of the characters "<" and ">" , which she will use on the design of her language, L++ :D.
She is using it as an abstraction for generating XML code Tags in an easier fashion and she understood that, for an expression to be valid, a "<" symbol must always have a corresponding ">" character somewhere (not necessary immediately) after it. Moreover, each ">" symbol should correspond to exactly one "<" symbol.
So, for instance, the instructions:
<<>> 
<> 
<><> 
are all valid. While:
>> 
><>< 
are not.
Given some expressions which represent some instructions to be analyzed by Lira's compiler, you should tell the length of the longest prefix of each of these expressions that is valid, or 0 if there's no such a prefix.

-----Input-----
Input will consist of an integer T denoting the number of test cases to follow.
Then, T strings follow, each on a single line, representing a possible expression in L++.

-----Output-----
For each expression you should output the length of the longest prefix that is valid or 0 if there's no such a prefix. 


-----Constraints-----
- 1 ≤ T ≤ 500
- 1 ≤ The length of a single expression ≤ 106
- The total size all the input expressions is no more than 5*106

-----Example-----
Input:
3
<<>>
><
<>>>
Output:
4
0
2

Difficulty: interview

Starter code:

Solutions:
# cook your dish here
t=int(input())
for j in range(t):
    s=input()
    st=[]
    ans=0

    for i in range(len(s)):
        
        if(s[i]=='>'):
            if(len(st)!=0 and st[-1]=='<'):
                st.pop()
                if(len(st)==0):
                    ans=i+1
            else:
                break

        else:
            st.append('<')

    print(ans)


# cook your dish here
for y in range(int(input())):
    s=input()
    st=[]
    i=-1
    a=0
    for x in range(len(s)):

        if i==-1 and s[x]=='>':
            
            break
        elif s[x]=='<':
            st.append('<')
            i+=1
        elif s[x]=='>':
            st.pop()
            i-=1
        if i==-1:
            a=x+1
    print(a)
        
            
    
            
            

# cook your dish here
for _ in range(0,int(input())):
    s=input()
    c=0
    ans=0
    for i in range(0,len(s)):
        if s[i]=="<":
            c=c+1
        else:
            c=c-1
        if c==0:
            ans=i+1
        elif c<0:
            break
    print(ans)
        

# cook your dish here
t=int(input())
for _ in range(t):
    s = input()
    count = 0
    l = []
    for i in range(0,len(s)):
        #print(l)
        if s[i] == ">":
            
            if len(l)!=0 and l[-1]=="<":
                #("jk")
                l.pop()
                if len(l)==0:
                    count = i+1
            else:
                break
                    
            
        else:
            l.append("<")
    print(count)

def compiler(string):
	t=0
	ans=0
	for i in range(len(string)):
		if string[i]=='<':
			t+=1
		else:
			t-=1
			if t==0:
				ans = max(ans, i+1)
			elif t<0:
				break
	return ans

t = int(input())
while t:
	string = input()
	print(compiler(string))
	t-=1


from sys import stdin, stdout 

def main():
    numberOfCases = int(stdin.readline())
    
    for i in range(0, numberOfCases):
        arr = [char for char in stdin.readline().strip()]
        starter = []
        count = 0
        currentCount = 0
        
        
        for element in arr:
            if element == "<":
                starter.append(element)
            else:
                if len(starter) == 0:
                    break
                starter.pop()
                
                if len(starter) == 0:
                    count = count + 2 + currentCount
                    currentCount = 0
                else :
                    currentCount += 2
        
        print(count)
                        
 
# call the main method
def __starting_point():
    main()    
__starting_point()

t = int(input())
for test in range(t):
    expression = list(input())
    available_left_arrow = 0
    streak = 0
    max_streak = 0
    for exp in expression:
        if exp == '<':
            available_left_arrow += 1
        else:
            if available_left_arrow <= 0:
                break
            available_left_arrow -= 1
            if available_left_arrow == 0:
                max_streak = max_streak + 2 + streak
                streak = 0
            else:
                streak += 2
            
    print(max_streak)
    

# cook your dish here
t=int(input())
for _ in range (t):
    x=input()
    t=0
    cnt=0
    lst=[]
    for i in x:
        if (i=='<'):
            lst.append(i)
        else:
            if len(lst)==0:
                break
            else:
                lst.pop()
                if len(lst)==0:
                    cnt+=2 + t
                    t = 0
                else:
                    t+=2
    print(cnt)

for _ in range(int(input())):
    s = input()
    st = []
    temp,count = 0,0
    for i in s:
        if i =='<':
            st.append('<')
        else:
            if len(st)==0:
                break
            else:
                st.pop()
                if len(st)==0:
                    count+=2 + temp
                    temp = 0
                else:
                    temp+=2
    print(count)

t = int(input())

while t:
    t -= 1 
    s = input()
    count = 0
    a = 0
    d = []
    for i in s:
        if i == '<':
            d.append('<')
        elif i == '>' and d == []:
            break
        else:
            d.pop(0)
            if d == []:
                count += 2 + a
                a = 0
            else:
                a += 2
    print(count)

t=int(input())
while t:
    a=list(map(str,input()))
    b=[]
    c,ans=0,0
    for i in range(len(a)):
        if a[i]=='<' :
            b.append(a[i])
            c+=1
        else:
            if len(b)==0 or b[-1]!='<' :
                break;
            else:
                b.pop()
                if len(b)==0:
                    ans+=2*c
                    c=0
    print(ans)
    t-=1

for i in range(int(input())):
    s = input()
    stack = []
    ans = 0
    c = 0
    for i in range(len(s)):
        if s[i] == "<":
            stack.append(s[i])
            c+=1
        else:
            if (len(stack) == 0) or (stack[-1]!="<"):
                break
            else:
                stack.pop()
                if len(stack) == 0:
                    ans+=(2*c)
                    c = 0
    print(ans)

for i in range(int(input())):
    s = input()
    stack = []
    ans = 0
    c = 0
    for i in range(len(s)):
        if s[i] == "<":
            stack.append(s[i])
            c+=1
        else:
            if (len(stack) == 0) or (stack[-1]!="<"):
                break
            else:
                stack.pop()
                if len(stack) == 0:
                    ans+=(2*c)
                    c = 0
    print(ans)

# cook your dish here
for i in range(int(input())):
    s = input()
    stack = []
    ans = 0
    c = 0
    for i in range(len(s)):
        if s[i] == "<":
            stack.append(s[i])
            c+=1
        else:
            if (len(stack) == 0) or (stack[-1]!="<"):
                break
            else:
                stack.pop()
                if len(stack) == 0:
                    ans+=(2*c)
                    c = 0
    print(ans)
        


# cook your dish here
t=int(input())
for i in range(0,t):
    s=input()
    l=[]
    f=0
    m=0
    for j in s:
        if j=="<":
            l.append("<")
        elif j==">" and len(l)>0:
            l=l[:-1]
            f=f+2
            if l==[]:
                m=f
        else:
            break
    print(m)
            
        

tc=int(input())
for q in range(tc):
        arr=input()
        stack=[]
        maxx=0
        counter=0
        for i in arr:
            
            counter+=1
            if(i=='<'):
                stack.append(i)
            elif(i=='>' and len(stack)):
                stack.pop()
                if(not stack):
                       maxx=counter
            else:
                  break
        print(maxx)

# cook your dish here
t=int(input())
for _ in range(t):
      s=input()
      l=[]
      c=0
      flag=0
      for i in range(len(s)):
            if s[i]=='<':
                  c+=1
            else:
                  c-=1
            if c==0:
                  flag=i+1
            if c<0:
                  break
      print(flag)

# cook your dish here
t=int(input())
for _ in range(t):
    s=input()
    l=[]
    c=0
    flag=0
    for i in range(len(s)):
        if s[i]=='<':
            c+=1
        else:
            c-=1
        if c==0:
            flag=i+1
        if c<0:
            break
    print(flag)

# cook your dish here
t=int(input())
for _ in range(t):
    s=input()
    l=[]
    c=0
    flag=0
    for i in range(len(s)):
        if s[i]=='<':
            c+=1
        else:
            c-=1
        if c==0:
            flag=i+1
        if c<0:
            break
    print(flag)

# cook your dish here
t=int(input())
for _ in range(t):
    s=input()
    l=[]
    c=0
    flag=0
    for i in range(len(s)):
        if s[i]=='<':
            c+=1
        else:
            c-=1
        if c==0:
            flag=max(flag,i+1)
        if c<0:
            break
    print(flag)

T = int(input())
while(T):
    check = []
    s = input()
    cur = 0
    long_prifix = 0
    for i in s:
        cur+=1
        if(i=='<'):
            check.append(i)    
        elif(i=='>' and len(check)):
            check.pop()
            if(not check):
                long_prifix = cur
        else:
            break    
    print(long_prifix)	
    T-=1

def solve(S):
  mystack = []
  ans = 0
  for i in range(len(S)):
    if(S[i] == "<"):
      mystack.append("<")
    else:
      if(len(mystack) == 0):
        return ans
      else:
        mystack.pop()
        if(len(mystack) == 0):
          ans = i+1
  return ans

  
T = int(input())

for j in range(T):
  print(solve(input()))

def solve(S):
  ans = 0
  t = 0 
  l = []

  for a in S:
    t += 1
    if a=='<':
      l.append(a)
    if a=='>':
      if len(l) == 0:
        return ans
        
      if len(l) > 0:
        l.pop()
        if len(l) == 0:
          ans = t
      
      
  return ans
  
  

T = int(input())
ls=list()

for i in range(T):
  print(solve(input()))
  # l=liinput()
  # ls.extend(l)