#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> low(n), high(n);
        for(int i=0; i<n; ++i)
            cin >> low[i] >> high[i];

        map<pair<int, int>, long long> m;
        m[make_pair(0, 1)] = 1;
        long long ans = 0;
        while(!m.empty()){
            map<pair<int, int>, long long> m2;
            for(const auto& p : m){
                int prev = p.first.first;
                bitset<32> bs = p.first.second;

                for(int a=0; a<=9; ++a){
                    bitset<32> bs2;
                    for(int i=0; i<n; ++i){
                        if(bs[2*i]){
                            if(0 < a)
                                bs2[2*i+1] = true;
                            if(low[i] <= a && a <= high[i])
                                bs2[2*(i+1)] = true;
                        }
                        if(bs[2*i+1]){
                            int x = prev * 10 + a;
                            if(low[i] <= x && x <= high[i])
                                bs2[2*(i+1)] = true;
                        }
                    }
                    if(bs2[2*n]){
                        ans += p.second;
                        bs2[2*n] = false;
                    }

                    if(bs2.any())
                        m2[make_pair(a, bs2.to_ulong())] += p.second;
                }
            }
            m.swap(m2);
        }
        cout << ans << endl;
    }
}