Tag based task aggregator

I’m literally in a car on my phone, so can only give some pointers from memory.

For 2.
?categories are page id’s
So can get their name:
[?categories :block/name ?catname]
And then compare:
[(= ?catname ?inputpage)]
(Ps. I think you miss that ?i is on page ?h?)

For 3.
How should I read this?
How are tasks tagged? Do you mean that a tasks should be tagged with input, but not with a master category?