I have simplified your schema to:
create table cat( id int, name varchar(100) );
create table tree ( id int , parent_id int);
create table item( id int, name varchar(100), cat_id int);
insert into cat values
( 1, 'HW'),
( 2, 'HW-PC'),
( 3, 'HW-M' ),
( 4, 'Soft'),
(5,'HW-M-N');
insert into tree values
(2,1),
(3,1),
(5,3);
insert into item values
( 1, 'A', 2),
( 2, 'B', 3);
The query you request, for root category = 1 is:
with child_id as
(
select parent_id as id
from tree
where parent_id = 1 --here cat = 1
union all
select tree.id
from child_id c
inner join tree on tree.parent_id = c.id
),
productes as (
select item.*,
row_number() over (order by item.id ) as rn --set your order criteria
from item
inner join child_id c on c.id = item.cat_id
)
select *
from productes
where rn = 1
| ID | NAME | CAT_ID | RN |
---------------------------
| 1 | A | 2 | 1 |