#include "bits/stdc++.h"
using namespace std;

const int maton_size = 10;
struct n_maton {
	int n_id;
	vector<vector<int>>edgess;
	n_maton(const int id_, const vector<vector<int>>edgess_) :n_id(id_), edgess(edgess_) {
		assert(maton_size + 1 == edgess.size());
	}
	n_maton() :n_id(0), edgess(maton_size+1) {}
};
struct nfa{
	struct d_maton {
		int d_id;
		vector<int>n_ids;
		vector<int>d_edges;
		d_maton(const int id_, const n_maton&mat) :d_id(id_), n_ids(1, mat.n_id),d_edges(maton_size) {}
		d_maton(const int id_, const vector<n_maton>&mats) :
			d_id(id_), n_ids(),d_edges(maton_size) {
			for (auto m : mats) {
				n_ids.emplace_back(m.n_id);
				vector<vector<int>>n_edgess;
				for (auto es : m.edgess) {
					for (int i = 0; i < maton_size + 1; ++i) {
						for (auto e : es) {
							n_edgess[i].push_back(e);
						}
					}
				}
				for (int i = 0; i < maton_size + 1; ++i) {
					sort(n_edgess[i].begin(), n_edgess[i].end());
					n_edgess[i].erase(unique(n_edgess[i].begin(), n_edgess[i].end()), n_edgess[i].end());
				}
			}
		}
		d_maton(const int id_, const vector<int>n_ids_) :
			d_id(id_), n_ids(n_ids_),d_edges(maton_size) {}
	};
	vector<n_maton>n_nodes;
	vector<d_maton>d_nodes;
	vector<int> get_epsilons(const vector<int>&now_n_ids) {
		vector<int>epsilons(n_nodes.size());
		queue<int>ep_que;
		for (auto n_id : now_n_ids) {
			epsilons[n_id] = true;
			ep_que.push(n_id);
		}
		while (!ep_que.empty()) {
			const int ep_n_id = ep_que.front();
			ep_que.pop();
			for (auto e : n_nodes[ep_n_id].edgess[maton_size]) {
				if (!epsilons[e]) {
					epsilons[e] = true;
					ep_que.push(e);
				}
			}
		}
		vector<int>eps_n_ids;
		for (int i = 0; i < static_cast<int>(n_nodes.size()); ++i) {
			if (epsilons[i])eps_n_ids.push_back(i);
		}
		return eps_n_ids;
	}
	vector<int>get_next_ids(const vector<int>&now_n_ids,const int n) {
		vector<int>next_n_ids;
		for (auto n_id:now_n_ids){
			for (auto e : n_nodes[n_id].edgess[n]) {
				next_n_ids.emplace_back(e);
			}
		}
		sort(next_n_ids.begin(), next_n_ids.end());
		next_n_ids.erase(unique(next_n_ids.begin(), next_n_ids.end()), next_n_ids.end());
		return next_n_ids;
	}
	nfa(const int num):n_nodes(num),d_nodes() {
		for (int i = 0; i < num; ++i)n_nodes[i].n_id = i;
	}
	nfa(const vector<n_maton>&n_mats) :n_nodes(n_mats) {
	}
	void add_edge(const int from, const int num,const int to) {
		n_nodes[from].edgess[num].push_back(to);
	}
	void make_dfa(const int start_id) {
		queue<int>que;
		vector<int>starts(1,n_nodes[0].n_id);
		starts = get_epsilons(starts);
		d_nodes.push_back(d_maton(0,n_nodes[0]));
		que.push(0);
		int num = 1;
		while (!que.empty()) {
			const int now_d_id = que.front();
			que.pop();
			for (int n = 0; n < maton_size; ++n) {
				vector<int>now_n_ids(d_nodes[now_d_id].n_ids);

				vector<int>next_n_ids = get_next_ids(now_n_ids, n);
				next_n_ids = get_epsilons(next_n_ids);
				auto it = find_if(d_nodes.begin(), d_nodes.end(), [=](const d_maton&mat) {
					return mat.n_ids == next_n_ids;
				});
				if (!next_n_ids.empty()) {
					if (it == d_nodes.end()) {
						d_nodes.emplace_back(num, next_n_ids);
						que.push(num);
						d_nodes[now_d_id].d_edges[n] = num;
						num++;
					}
					else {
						d_nodes[now_d_id].d_edges[n] = it - d_nodes.begin();
					}
				}
				else {
					d_nodes[now_d_id].d_edges[n] = -1;
				}
			}
		}
	}
};
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		const int ps = 0;
		const int ss = ps+N+1;
		const int rs = ss + N;
		const int qs = rs + N;
		vector<n_maton>matons(qs + N);
		nfa anfa(qs + N);
		
		for (int i = 0; i < N; ++i) {
			int l, r; cin >> l >> r;
			//1~9
			if (r < 10) {
				for (int n = l; n <= r; ++n) {
					anfa.add_edge(ps + i, n, ps + i + 1);
				}
			}
			else {
				if (l < 10) {
					for (int n = l; n <= 9; ++n) {
						anfa.add_edge(ps + i, n, ps + i + 1);
					}
				}
				l = max(l, 10); r = max(r, 10);
				if (l / 10 == r / 10) {
					anfa.add_edge(ps + i, l / 10, ss + i);
					for (int n = l % 10; n <= r % 10; ++n) {
						anfa.add_edge(ss + i, n, ps + i + 1);
					}
				}
				else {
					anfa.add_edge(ps + i, l / 10, qs + i);
					for (int n = l % 10; n < 10; ++n) {
						anfa.add_edge(qs + i, n, ps + i + 1);
					}
					for (int m = l / 10 + 1; m < r / 10; ++m) {
						anfa.add_edge(ps + i, m, rs + i);
						for (int n = 0; n < 10; ++n) {
							anfa.add_edge(rs + i, n, ps + i + 1);
						}
					}
					anfa.add_edge(ps + i, r / 10, ss + i);
					for (int n = 0; n <= r % 10; ++n) {
						anfa.add_edge(ss + i, n, ps + i + 1);
					}
				}
				
			}
		}
		anfa.make_dfa(0);
		vector<int>goals(anfa.d_nodes.size());
		vector < vector<int>>edges(anfa.d_nodes.size());
		vector<int>nums(anfa.d_nodes.size());
		vector<long long int>memos(anfa.d_nodes.size());
		for (auto n : anfa.d_nodes) {
			if (find(n.n_ids.begin(), n.n_ids.end(), ss - 1) != n.n_ids.end()) {
				goals[n.d_id] = true;
			}
			for (auto e : n.d_edges) {
				if (e != -1) {
					edges[n.d_id].push_back(e);
					nums[e]++;
				}
			}
		}
		long long int ans = 0;
		queue<int>que;
		for (int i = 0; i < nums.size(); ++i) {
			if (!nums[i]) {
				que.push(i);
				memos[i] = 1;
			}
		}
		while (!que.empty()) {
			int n = que.front();
			que.pop();
			if (goals[n])ans += memos[n];
			for (auto e : edges[n]) {
				memos[e] += memos[n];
				nums[e]--;
				if (!nums[e]) {
					que.push(e);
				}
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3252