Tip={{1,0,0,0},{0,1,0,0},{0,0,1,di},{0,0,0,1}}

Tpq={{ci,-si,0,0},{si,ci,0,0},{0,0,1,0},{0,0,0,1}}

Tqr={{1,0,0,aimin1},{0,1,0,0},{0,0,1,0},{0,0,0,1}}

Tri={{1,0,0,0},{0,c(alfimin1),-s(alfimin1),0},{0,s(alfimin1),c(alfimin1),0},{0,0,0,1}}

T=Tri.Tqr.Tpq.Tip

linktransT=T/.{ci->Cos[i],si->Sin[i],c(alfimin1)->Cos[alfimin1],
s(alfimin1)->Sin[alfimin1]}

Trans=linktransT/.{si->Sin[i],ci->Cos[i]}

Substituting DH
Solve each for each translation from T01->T54

T10=Trans/.{alfimin1->0,aimin1->0,di->0,i->t1}/.{Sin[t1]->s1,
Cos[t1]->c1}

T21=Trans/.{alfimin1->Pi/2, aimin1->0, di->0, i->t2}/.{Sin[t2]->s2,
Cos[t2]->c2}

T32=Trans/.{alfimin1->-Pi/2, aimin1->0, di->0, i->t3}/.{Sin[t3]->s3,
Cos[t3]->c3}

T43=Trans/.{alfimin1->Pi/2, aimin1->0, di->d4, i->t4}/.{Sin[t4]->s4,
Cos[t4]->c4}

T54=Trans/.{alfimin1->-Pi/2, aimin1->0, di->0, i->t5}/.{Sin[t5]->s5,
Cos[t5]->c5}

Solve for T50

T50=T10.T21.T32.T43.T54

Have T50... Huge!
Now dirive subresults

T53=T43.T54

matT53=MatrixForm[T53]

T31=T21.T32

T51=T31.T53