UTF-8 is one of the methods for coding multibyte characters.

Characters are treated as bytes on the computer. If it is only English, it can be expressed in 1 byte even if the Latin alphabet, numbers and symbols are combined, but unfortunately it is not possible to express the characters used all over the world in 1 byte, so the characters are expressed using multiple bytes. There is a need.

Here, for example, when a 2-byte string of 12354 (0x3042) is assigned to the character "a", if the byte strings are arranged as they are, it is indistinguishable whether it is 2 characters with 0x30,0x42 or 1 character with 0x3042.

For this reason, UTF-8, which is a multi-byte character encoding method, overcomes this problem by making it possible to know the length of the byte string that continues in the first byte. The specific bit pattern is as follows.

Byte length | Bit pattern
--- | ---
1 | 0xxxxxxx
2 | 110yyyyx 10xxxxxx
3 | 1110yyyy 10yxxxxx 10xxxxxx
4 | 11110yyy 10yyxxxx 10xxxxxx 10xxxxxx

Here, x is an arbitrary bit of 0/1. Also, y can be any bit of 0/1, but one of them must be 1. It is assumed that all characters are 1, 2, 3, or 4-byte characters.

Here, the restriction that at least one bit of y is 1 is due to the following reasons. For example, when encoding'/' (0x2f) into a byte string, there are two methods, 0x2f and 1-byte coding, or 0xc0 0xaf and 2-byte coding, but allowing such ambiguity is for security reasons. This is because it may be a source of threats.

After hearing the above story, you were wondering how much freedom UTF-8 has. Specifically, how many combinations of bytes are possible as UTF-8 when some bits of a given byte sequence are unknown.

At this time, find the number of possible combinations of byte strings and output the remainder divided by 1,000,000.

Notes on Test Cases

Multiple datasets are given in the above input format. Create a program that outputs each data set in the above output format.

When N is 0, it indicates the end of input.

<!-



Input


N
b1
b2
...
bN

N is the number of bytes and bi is the bytes. 1 ≤ N ≤ 1000 is satisfied. For bi, eight symbols {0/1 / x} are lined up. x indicates that the bit is unknown.

Output

Output the remainder of dividing the number of possible byte string combinations by 1,000,000.

Examples

Input

1
xxxxxxxx
3
11100000
10x00000
10111111
3
11100000
10000000
10111111
4
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
0


Output

128
1
0
778240


Input

1
xxxxxxxx


Output

128


Input

3
11100000
10x00000
10111111


Output

1


Input

3
11100000
10000000
10111111


Output

0


Input

4
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx


Output

778240
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll memo[1001];
int calc(int idx, vector<string>& v){
  int N = v.size();
  if(idx == N) return 1;
  if(memo[idx] != -1) return memo[idx];
  ll &res = memo[idx];
  res = 0;
  string s;
  string mask[4] = {
    "0xxxxxxx",
    "110yyyyx10xxxxxx",
    "1110yyyy10yxxxxx10xxxxxx",
    "11110yyy10yyxxxx10xxxxxx10xxxxxx"
  };
  for(int l = 0; l < 4; l++){
    if(idx + l == N) return res;
    s += v[idx + l];
    bool y_judge[256] = {};
    bool ok = true;
    REP(i, mask[l].size()) {
      if(mask[l][i] == 'y'){
        y_judge[s[i]] = true;
      }
      if(mask[l][i] == '0' && s[i] == '1') ok = false;
      if(mask[l][i] == '1' && s[i] == '0') ok = false;
    }
    if(l >= 1 && !y_judge['x'] && !y_judge['1']) ok = false;
    if(!ok) continue;
    ll cnt1 = 1, cnt2 = 1;
    REP(i, mask[l].size()){
      if(mask[l][i] == 'y' && s[i] == 'x') cnt1 <<= 1;
      if(mask[l][i] == 'x' && s[i] == 'x') cnt2 <<= 1;
    }
    if(l >= 1 && !y_judge['1']) cnt1--;
    res += cnt1 * cnt2 * calc(idx + 1 + l, v);
    res %= 1000000;
  }
  return res;
}
int main(){
  int N;
  while(cin>>N && N){
    vector<string> v(N);
    REP(i, N) cin>>v[i];
    memset(memo, -1, sizeof(memo));
    cout<<calc(0, v)<<endl;
  }
  return 0;
}