#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define mp make_pair
#define ii pair<ll, ll>
#define MOD 998244353LL
#define oo (10000000000000000LL)

ll c = 1;
ll x, y;
string s;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        cin >> x >> y >> s;
        ll res = -1;
        for(int i = 0; i < s.size(); i++)
        {
            if(s[i] == 'N')
                y++;
            else if(s[i] == 'S')
                y--;
            else if(s[i] == 'E')
                x++;
            else
                x--;
            if(abs(x) + abs(y) <= i + 1)
            {
                res = i + 1;
                break;
            }
        }
        cout << "Case #" << c++ << ": ";
        if(res == -1)
            cout << "IMPOSSIBLE" << endl;
        else
            cout << res << endl;
    }

    return 0;
}
