Problem Statement

Dr. Suposupo developed a programming language called Shipura. Shipura supports only one binary operator ${\tt >>}$ and only one unary function ${\tt S<\ >}$.

$x {\tt >>} y$ is evaluated to $\lfloor x / 2^y \rfloor$ (that is, the greatest integer not exceeding $x / 2^y$), and ${\tt S<} x {\tt >}$ is evaluated to $x^2 \bmod 1{,}000{,}000{,}007$ (that is, the remainder when $x^2$ is divided by $1{,}000{,}000{,}007$).

The operator ${\tt >>}$ is left-associative. For example, the expression $x {\tt >>} y {\tt >>} z$ is interpreted as $(x {\tt >>} y) {\tt >>} z$, not as $x {\tt >>} (y {\tt >>} z)$. Note that these parentheses do not appear in actual Shipura expressions.

The syntax of Shipura is given (in BNF; Backus-Naur Form) as follows:


expr   ::= term | expr sp ">>" sp term
term   ::= number | "S" sp "<" sp expr sp ">"
sp     ::= "" | sp " "
number ::= digit | number digit
digit  ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

The start symbol of this syntax is $\tt expr$ that represents an expression in Shipura. In addition, $\tt number$ is an integer between $0$ and $1{,}000{,}000{,}000$ inclusive, written without extra leading zeros.

Write a program to evaluate Shipura expressions.

Input

The input is a sequence of datasets. Each dataset is represented by a line which contains a valid expression in Shipura.

A line containing a single ${\tt \\#}$ indicates the end of the input. You can assume the number of datasets is at most $100$ and the total size of the input file does not exceed $2{,}000{,}000$ bytes.

Output

For each dataset, output a line containing the evaluated value of the expression.

Sample Input


S< S< 12 >> 2 > >
123 >> 1 >> 1
1000000000   >>129
S<S<S<S<S<2>>>>>
S  <S< S<2013    >>> 11 >>> 10 >


Output for the Sample Input


81
30
0
294967268
14592400





Example

Input

S< S< 12 >> 2 > >
123 >> 1 >> 1
1000000000   >>129
S<S<S<S<S<2>>>>>
S  <S< S<2013    >>> 11 >>> 10 >
#


Output

81
30
0
294967268
14592400
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"



int l = 0;
int r;
vector<int>nums;
string st;
string nspace() {
	string ans;
	for (auto c : st) {
		if (c != ' ')ans.push_back(c);
	}
	return ans;
}
int a = 0;
long long int getnum() {
	long long int num = 0;
	while (a!=st.size()&&isdigit(st[a])) {
		num = num * 10 + st[a] - '0';
		a++;
	}
	return num;
}
long long int getexpr(bool need,const int ba) {
	long long int num;
	while (a != st.size()) {
		if (st[a] == 'S') {
			a++;
			assert(st[a] == '<');
			a++;
			num = getexpr(true, nums[a - 1]);
			num = num*num % 1000000007;
			a++;
		}
		else if (st[a] == '>') {
			if (a == ba) {
				return num;
			}
			else if (nums[a] == -1) {
				if (need) {

					a++;
					assert(st[a] == '>');
					a++;
					const int eva = int(min(31ll, getexpr(false, nums[a - 1])));
					num = num >> eva;
				}
				else {
					return num;
				}
			}
			else {
				if (!need) {
					return num;
				}
				assert(false);
			}
		}
		else if (isdigit(st[a])) {
			num = getnum();
			if (!need)return num;
		}
		else {
			assert(false);
		}
	}
	return num;

}
int main() {
	while (1) {

		getline(cin, st);
		if (st == "#")break;
		st = nspace();
		l = 0;
		r = st.size() - 1;
		nums.resize(st.size());
		fill(nums.begin(), nums.end(), -1);

		int count = 0;
		vector<bool>rels(st.size(),true);
		for (int i = 3; i < st.size(); ++i) {
			if (st[i] == 'S' || isdigit(st[i])) {
				if (st[i - 1] == '>'&&st[i - 2] == '>') {
					rels[i - 1] = false;
					rels[i - 2] = false;
				}
			}
		}
		stack<int>sta;
		for (int i = 0; i < st.size(); ++i) {
			if (st[i] == '<') {
				if (rels[i]) {
					sta.push(i);
				}
			}
			else if (st[i] == '>') {
				if (rels[i]) {
					int f = sta.top();
					nums[f] = i;
					nums[i] = f;
					sta.pop();
				}
			}
		}
		a = 0;
		long long int ans=getexpr(true,-1);
		cout << ans << endl;
	}
	return 0;
}