How to create an advanced route with query strings?
You can do this completely in the template. Have the structure entries resolve to a route like gallery/_router and then inside that template you could use this code to include the template of your choice:

{% switch craft.app.request.getParam('type') %}

    {% case "gallery" %}

        {% include "gallery/_entry" %}    

    {% case "anotherParam" %}

        {% include "gallery/_anotherParam" %}

     {% default %}

        {% include "gallery/_default" %}   

{% endswitch %}