SaMer is building a simple robot that can move in the four directions: up (^), down (v), left (<), and right (>). The robot receives the commands to move as a string and executes them sequentially. The robot skips the commands that make it go outside the table.

SaMer has an R×C table and a string of instructions. He wants to place the robot on some cell of the table without rotating it, such that the robot will skip the minimum number of instructions. Can you help him find the number of instructions that will be skipped by the robot if it was placed optimally?

Input
The first line of input contains a single integer T, the number of test cases.

Each test case contains two space-separated integers R and C (1 ≤ R, C ≤ 105), the number of rows and the number of columns in the table, followed by a non-empty string of no more than 200000 characters representing the initial instructions. The instructions are executed in the given order from left to right.

Output
For each test case, print the minimum number of instructions which will be skipped, on a single line.

Example
Input
2
2 2 >^^^

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
#include <cmath>
#include <queue>
#define mod 1000000007
using namespace std;
//贪心的
//x,y表示机器人的位置
//该地图在第四象限
//up down left right分别表示机器人在该方向上走过的最大位置
//例如当机器人走到下界,并且当前轨迹已经达到地图的最大界限时
//机器人需要在当前位置停下,结果+1
int main()
{
    char a[200010];
    int t,n,m,i,s;
    int up,down,left,right;
    scanf("%d",&t);
    while(t--)
    {
         up = down = left = right = 0;
         x = y= 0;
         s =0;
            scanf("%d%d",&n,&m);
            scanf("%s",a);
            for(int i=0;i<strlen(a);i++)
            {
                if(a[i]=='v')
                {
                    if(up-down+1==n&&x==down)s++;
                    else
                    {
                        x--;
                        down = min(down,x);
                    }
                }
                else if(a[i]=='<')
                {
                    if(right-left+1==m&&y==left)
                    {
                        s++;
                    }
                    else
                    {
                        y--;
                        left = min(y,left);
                    }
                }
                else if(a[i]=='>')
                {
                     if(right-left+1==m&&y==right)
                    {
                        s++;
                    }
                    else
                    {
                        y++;
                        right = max(y,right);
                    }
                }
                else
                {
                     if(up-down+1==n&&x==up)s++;
                    else
                    {
                        x++;
                        up = max(up,x);
                    }
                }
            }
            printf("%d\n",s);
    }
    return 0;
}