#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 1000


int main() {
	long long n;
	long long m[15][10][10];
	long long dp[12][4096][10];
	long long lo[7];
	long long hi[7];
	long long p2[15];
	long long x, y, z, s, ans;
	p2[0] = 1;
	f(i, 14)p2[i + 1] = p2[i] * 2;
	while(true) {
		ans = 0;
		scanf("%lld", &n);
		if (n == 0)return 0;
		f(i, n)scanf("%lld %lld", &lo[i], &hi[i]);
		f(i, 15) {
			f(ii, 10) {
				f(jj, 10)m[i][ii][jj] = 0;
			}
		}
		f(i, (2 * n) - 1) {
			f(ii, 10) {
				f(jj, 10) {
					if (i % 2 == 0) {
						if (ii == 0)m[i][ii][jj] = 0;
						else {
							x = 10 * ii + jj;
							y = i / 2;
							if ((lo[y] <= x) && (x <= hi[y]))m[i][ii][jj] = p2[i + 1];
							else m[i][ii][jj] = 0;
						}
					}
					else {
						m[i][ii][jj] = 0;
						if (jj != 0) {
						x = jj;
						y = (i + 1) / 2;
						if ((lo[y] <= x) && (x <= hi[y]))m[i][ii][jj] += p2[i + 2];
						x = 10 * jj;
						if ((lo[y] <= (x + 9)) && (x <= hi[y]))m[i][ii][jj] += p2[i + 1];
						}
					}
				}
			}
		}
		f(i, 12) {
			f(j, 4096) {
				f(ii, 10)dp[i][j][ii] = 0;
			}
		}
		for (long long i = 1; i <= 9; i++) {
			z = 0;
			x = i;
			if ((lo[0] <= x) && (x <= hi[0]))z += 2;
			x = 10 * i;
			if ((lo[0] <= (x + 9)) && (x <= hi[0]))z += 1;
			if (z > 0)dp[0][z][i] = 1;
		}
		f(i, 2 * n) {
			f(j, p2[(2 * n)]) {
				f(ii, 10) {
					if (dp[i][j][ii] > 0) {
						f(jj, 10) {
							x = j;
							y = 0;
							f(iii, 2 * n) {
								if (x % 2 == 1) {
									if (iii == ((2 * n) - 1)){
                                     if(jj==0) ans += dp[i][j][ii];
                                    }
									else {
										y = (y | m[iii][ii][jj]);
									}
								}
								x /= 2;
							}
							if (y > 0)dp[i + 1][y][jj] += dp[i][j][ii];
						}
					}
				}
			}
		}
		printf("%lld\n", ans);
	}


	return 0;
}
