Buggy python submission (verdict: Runtime Error):
d = {1:{1:'.',2:',',3:'!',4:'?',5:' '},
     2:{1:'a',2:'b',3:'c'},
     3:{1:'d',2:'e',3:'f'},
     4:{1:'g',2:'h',3:'i'},
     5:{1:'j',2:'k',3:'l'},
     6:{1:'m',2:'n',3:'o'},
     7:{1:'p',2:'q',3:'r',4:'s'},
     8:{1:'t',2:'u',3:'v'},
     9:{1:'w',2:'x',3:'y',4:'z'}
}
n = int(raw_input())
for i in range(n):
    mes = raw_input()
    mes = mes.split("0")
    mes=filter(lambda x:len(x)>0,mes)
    #print mes
    l=[]
    for e in mes:
        l.append([e[0], len(e)])
    res=""
    for e in l:
        i=int(e[0])
        if(i==1):
            if e[1]>5:x=e[1]%5
            else:x=e[1]
        elif(i==7 or i==9):
            if e[1]>4:x=e[1]%4
            else:x=e[1]
        else:
            if e[1]>3:x=e[1]%3
            else:x=e[1]
        res=res+d[i][x]

    print res

Fixed submission:
d = {1:{1:'.',2:',',3:'!',4:'?',5:' '},
     2:{1:'a',2:'b',3:'c'},
     3:{1:'d',2:'e',3:'f'},
     4:{1:'g',2:'h',3:'i'},
     5:{1:'j',2:'k',3:'l'},
     6:{1:'m',2:'n',3:'o'},
     7:{1:'p',2:'q',3:'r',4:'s'},
     8:{1:'t',2:'u',3:'v'},
     9:{1:'w',2:'x',3:'y',4:'z'}
}
n = int(raw_input())
for i in range(n):
    mes = raw_input()
    mes = mes.split("0")
    mes=filter(lambda x:len(x)>0,mes)
    l=[]
    for e in mes:
        l.append([e[0], len(e)])
    res=""
    for e in l:
        i=int(e[0])
        if(i==1):
            if e[1]%5==0:x=5
            else:x=e[1]%5
        elif(i==7 or i==9):
            if e[1]%4==0:x=4
            else:x=e[1]%4
        else:
            if e[1]%3==0:x=3
            else:x=e[1]%3
        res=res+d[i][x]

    print res

Buggy python submission (verdict: Runtime Error):
d = {1:{1:'.',2:',',3:'!',4:'?',5:' '},
     2:{1:'a',2:'b',3:'c'},
     3:{1:'d',2:'e',3:'f'},
     4:{1:'g',2:'h',3:'i'},
     5:{1:'j',2:'k',3:'l'},
     6:{1:'m',2:'n',3:'o'},
     7:{1:'p',2:'q',3:'r',4:'s'},
     8:{1:'t',2:'u',3:'v'},
     9:{1:'w',2:'x',3:'y',4:'z'}
}
n = int(raw_input())
for i in range(n):
    mes = raw_input()
    mes = mes.split("0")
    mes=filter(lambda x:len(x)>0,mes)
    l=[]
    for e in mes:
        l.append([e[0], len(e)])
    res=""
    for e in l:
        i=int(e[0])
        if(i==1):
            if e[1]>5:x=e[1]%5
            else:x=e[1]
        elif(i==7 or i==9):
            if e[1]>4:x=e[1]%4
            else:x=e[1]
        else:
            if e[1]>3:x=e[1]%3
            else:x=e[1]
            res=res+d[i][x]

    print res

Fixed submission:
d = {1:{1:'.',2:',',3:'!',4:'?',5:' '},
     2:{1:'a',2:'b',3:'c'},
     3:{1:'d',2:'e',3:'f'},
     4:{1:'g',2:'h',3:'i'},
     5:{1:'j',2:'k',3:'l'},
     6:{1:'m',2:'n',3:'o'},
     7:{1:'p',2:'q',3:'r',4:'s'},
     8:{1:'t',2:'u',3:'v'},
     9:{1:'w',2:'x',3:'y',4:'z'}
}
n = int(raw_input())
for i in range(n):
    mes = raw_input()
    mes = mes.split("0")
    mes=filter(lambda x:len(x)>0,mes)
    l=[]
    for e in mes:
        l.append([e[0], len(e)])
    res=""
    for e in l:
        i=int(e[0])
        if(i==1):
            if e[1]%5==0:x=5
            else:x=e[1]%5
        elif(i==7 or i==9):
            if e[1]%4==0:x=4
            else:x=e[1]%4
        else:
            if e[1]%3==0:x=3
            else:x=e[1]%3
        res=res+d[i][x]

    print res