#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct TopologicalSort{
  Int n;
  vector<set<Int> > G;
  vector<bool> used;
  vector<Int> indeg,p;
  
  TopologicalSort(){}
  TopologicalSort(Int sz):n(sz),G(n),used(n),indeg(n),p(0){}

  void add_edge(Int s,Int t){
    G[s].insert(t);
  }
  
  void bfs(Int s){
    queue<Int> q;
    q.push(s);
    used[s]=1;
    while(!q.empty()){
      Int v=q.front();q.pop();
      p.push_back(v);
      for(Int u:G[v]){
        indeg[u]--;
        if(indeg[u]==0&&!used[u]){
          used[u]=1;
          q.push(u);
        }
      }
    }
  }
  
  vector<Int>  build(){
    fill(used.begin(),used.end(),0);
    fill(indeg.begin(),indeg.end(),0);
    
    for(Int i=0;i<n;i++)
      for(Int v:G[i]) indeg[v]++;
    
    for(Int i=0;i<n;i++)
      if(indeg[i]==0&&!used[i]) bfs(i);
    
    return p;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n;
  while(cin>>n,n){
    vector<Int> ls(n+1),hs(n+1);
    for(Int i=1;i<=n;i++) cin>>ls[i]>>hs[i];

    vector<Int> as(n+1),bs(n+1);
    vector<Int> a0(n+1),b0(n+1);
    vector<Int> a1(n+1),b1(n+1);
    vector<Int> a2(n+1),b2(n+1);
    for(Int i=1;i<=n;i++){
      a0[i]=ls[i]%10;
      b0[i]=10;
      if((ls[i]/10)==(hs[i]/10)) b0[i]=hs[i]%10+1;
    
      a1[i]=0;
      b1[i]=10;    
      a2[i]=0;
      b2[i]=hs[i]%10+1;
       
      if(ls[i]>=10){
        as[i]=10;bs[i]=-1;
        continue;
      }
      as[i]=ls[i];
      if(hs[i]>=10) bs[i]=10;
      else bs[i]=hs[i]+1;
    }

    auto calc=[&](Int k,Int p){return k*7+p;};  
    Int G[100][10]={};  
    for(Int i=1;i<=n;i++){
    
      for(Int c=0;c<10;c++){
        if(a0[i]<=c&&c<b0[i])
          G[calc(i,0)][c]|=1LL<<calc(i,3);
        if(a1[i]<=c&&c<b1[i])
          G[calc(i,1)][c]|=1LL<<calc(i,4);
        if(a2[i]<=c&&c<b2[i])
          G[calc(i,2)][c]|=1LL<<calc(i,5);
      }    
    
      if(i+1<=n){
        for(Int j=3;j<7;j++){
          for(Int c=0;c<10;c++){
            Int x=ls[i+1]/10;
            Int y=hs[i+1]/10;
        
            if(c==x&&x!=0)
              G[calc(i,j)][c]|=1LL<<calc(i+1,0);

            if(x<c&&c<y)
              G[calc(i,j)][c]|=1LL<<calc(i+1,1);
        
            if(x!=y&&c==y&&y!=0)
              G[calc(i,j)][c]|=1LL<<calc(i+1,2);
        
            if(as[i+1]<=c&&c<bs[i+1])
              G[calc(i,j)][c]|=1LL<<calc(i+1,6);
          }
        }
      }
    }
    
    for(Int c=0;c<10;c++){
      Int x=ls[1]/10;
      Int y=hs[1]/10;
        
      if(c==x&&x!=0)
        G[0][c]|=1LL<<calc(1,0);

      if(x<c&&c<y)
        G[0][c]|=1LL<<calc(1,1);
        
      if(x!=y&&c==y&&y!=0)
        G[0][c]|=1LL<<calc(1,2);
        
      if(as[1]<=c&&c<bs[1])
        G[0][c]|=1LL<<calc(1,6);
    }
     
    vector<Int> rev;
    map<Int, Int> idx;  
    idx[1]=rev.size();
    rev.emplace_back(1);
  
    TopologicalSort ts(1000);
    set<Int> used;
    queue<Int> que;
    used.emplace(1);
    que.emplace(1);
    while(!que.empty()){
      Int bit=que.front();que.pop();
      for(Int c=0;c<10;c++){
        Int nxt=0;
        for(Int i=0;i<60;i++)
          if((bit>>i)&1) nxt|=G[i][c];      
        if(nxt==0) continue;
        if(!idx.count(nxt)){
          idx[nxt]=rev.size();
          rev.emplace_back(nxt);
        }
        ts.add_edge(idx[bit],idx[nxt]);
        if(used.count(nxt)) continue;
        used.emplace(nxt);        
        que.emplace(nxt);
      }
    }
    //cout<<"sz:"<<rev.size()<<endl;

    vector<Int> ord=ts.build();  
    vector<Int> dp(ts.G.size(),0);
    dp[0]=1;  
    for(Int x:ord){
      if(x>=(Int)rev.size()) continue;
      //cout<<x<<":"<<dp[x]<<endl;
      
      Int bit=rev[x];    
      for(Int c=0;c<10;c++){
        Int nxt=0;
        for(Int i=0;i<60;i++)
          if((bit>>i)&1) nxt|=G[i][c];      
        if(nxt==0) continue;
        
        dp[idx[nxt]]+=dp[x];      
      }
    }
  
    Int ans=0;
    for(Int i=0;i<(Int)rev.size();i++){
      Int flg=0,bit=rev[i];
      for(Int j=3;j<7;j++)
        if((bit>>calc(n,j))&1) flg=1;
      if(flg) ans+=dp[i];    
    }  
    cout<<ans<<endl;
    //break;
  }
  return 0;
}



Measured memory_bytes: 3352