Assuming that the table has an identity col to identify each row.
with cte (id, dln, sln)
as
(
select id, dense_rank() over (partition by doc_no order by stk_code asc) as dln
, row_number() over (partition by doc_no, stk_code order by serial_no asc) as sln
from @t_test
)
update @t_test
set doc_lineno = cte.dln
, stk_lineno = cte.sln
from @t_test as t
inner join cte as cte
on t.id = cte.id
;