QueryBadFormed: A bad request has been sent to the endpoint: probably the SPARQL query is badly formed.

Response:
b'SPARQL-QUERY: queryStr=#\nPREFIX biopax: <http://www.biopax.org/release/biopax-level3.owl#>\nPREFIX bd: <http://www.bigdata.com/rdf#>\nPREFIX cc: <http://creativecommons.org/ns#>\nPREFIX datacite: <http://purl.org/spar/datacite/>\nPREFIX dblp: <https://dblp.org/rdf/schema#>\nPREFIX dc:    <http://purl.org/dc/elements/1.1/>\nPREFIX dct: <http://purl.org/dc/terms/>\nPREFIX freq:  <http://purl.org/cld/freq/>\nPREFIX geo: <http://www.opengis.net/ont/geosparql#>\nPREFIX geom: <http://geovocab.org/geometry#>\nPREFIX gpml:  <http://vocabularies.wikipathways.org/gpml#>\nPREFIX litre: <http://purl.org/spar/literal/> \nPREFIX lgdo: <http://linkedgeodata.org/ontology/>\nPREFIX ontolex: <http://www.w3.org/ns/lemon/ontolex#>\nPREFIX orkgp: <http://orkg.org/orkg/predicate/>\nPREFIX orkgc: <http://orkg.org/orkg/class/>\nPREFIX orkgr: <http://orkg.org/orkg/resource/>\nPREFIX owl: <http://www.w3.org/2002/07/owl#>\nPREFIX p: <http://www.wikidata.org/prop/>\nPREFIX pav: <http://purl.org/pav/>\nPREFIX pq: <http://www.wikidata.org/prop/qualifier/>\nPREFIX pqn: <http://www.wikidata.org/prop/qualifier/value-normalized/>\nPREFIX pqv: <http://www.wikidata.org/prop/qualifier/value/>\nPREFIX pr: <http://www.wikidata.org/prop/reference/>\nPREFIX prn: <http://www.wikidata.org/prop/reference/value-normalized/>\nPREFIX prov: <http://www.w3.org/ns/prov#>\nPREFIX prv: <http://www.wikidata.org/prop/reference/value/>\nPREFIX ps: <http://www.wikidata.org/prop/statement/>\nPREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>\nPREFIX psv: <http://www.wikidata.org/prop/statement/value/>\nPREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\nPREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX schema: <http://schema.org/>\nPREFIX skos: <http://www.w3.org/2004/02/skos/core#>\nPREFIX void:  <http://rdfs.org/ns/void#>\nPREFIX vrank: <http://purl.org/voc/vrank#>\nPREFIX wd: <http://www.wikidata.org/entity/>\nPREFIX wdata: <http://www.wikidata.org/wiki/Special:EntityData/>\nPREFIX wdno: <http://www.wikidata.org/prop/novalue/>\nPREFIX wdref: <http://www.wikidata.org/reference/>\nPREFIX wds: <http://www.wikidata.org/entity/statement/>\nPREFIX wdt: <http://www.wikidata.org/prop/direct/>\nPREFIX wdtn: <http://www.wikidata.org/prop/direct-normalized/>\nPREFIX wdv: <http://www.wikidata.org/value/>\nPREFIX wikibase: <http://wikiba.se/ontology#>\nPREFIX wp: <http://vocabularies.wikipathways.org/wp#>\nPREFIX wprdf: <http://rdf.wikipathways.org/>\nPREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n\n#defaultView:Graph\nPREFIX gas: <http://www.bigdata.com/rdf/gas#>\n\nSELECT ?author ?authorLabel ?work ?workLabel \nWITH {\n SELECT ?work ?author WHERE { \n  { }\n  {% for q1 in qs %} {% for q2 in qs %} {% if q1 < q2 %} UNION {\n   SELECT ?work ?author WHERE {\n    SERVICE gas:service {\n     gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.BFS" ;\n           gas:in wd:{{ q1 }} ;\n           gas:target wd:{{ q2 }} ;\n           gas:traversalDirection "Undirected" ;\n           gas:out ?work ;\n           gas:linkType wdt:P50 ;\n          gas:maxVisited 5000 .\n    }\n    ?work wdt:P50 ?author\n   }\n  } # UNION END\n  {% endif %} {% endfor %}  {% endfor %}  } \n} AS %result \nWHERE {\n INCLUDE %result \n SERVICE wikibase:label { bd:serviceParam wikibase:language "en,da,de,es,fr,he,jp,nl,no,ru,sv,zh" . }\n}\n\njava.util.concurrent.ExecutionException: org.openrdf.query.MalformedQueryException: Lexical error at line 58, column 5.  Encountered: " " (32), after : "%"\n\tat java.util.concurrent.FutureTask.report(FutureTask.java:122)\n\tat java.util.concurrent.FutureTask.get(FutureTask.java:206)\n\tat com.bigdata.rdf.sail.webapp.BigdataServlet.submitApiTask(BigdataServlet.java:292)\n\tat com.bigdata.rdf.sail.webapp.QueryServlet.doSparqlQuery(QueryServlet.java:678)\n\tat com.bigdata.rdf.sail.webapp.QueryServlet.doPost(QueryServlet.java:275)\n\tat com.bigdata.rdf.sail.webapp.RESTServlet.doPost(RESTServlet.java:269)\n\tat com.bigdata.rdf.sail.webapp.MultiTenancyServlet.doPost(MultiTenancyServlet.java:195)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:707)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:790)\n\tat org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1655)\n\tat org.wikidata.query.rdf.blazegraph.throttling.ThrottlingFilter.doFilter(ThrottlingFilter.java:322)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)\n\tat org.wikidata.query.rdf.blazegraph.throttling.SystemOverloadFilter.doFilter(SystemOverloadFilter.java:84)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)\n\tat ch.qos.logback.classic.helpers.MDCInsertingServletFilter.doFilter(MDCInsertingServletFilter.java:50)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)\n\tat org.wikidata.query.rdf.blazegraph.filters.QueryEventSenderFilter.doFilter(QueryEventSenderFilter.java:123)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)\n\tat org.wikidata.query.rdf.blazegraph.filters.ClientIPFilter.doFilter(ClientIPFilter.java:43)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)\n\tat org.wikidata.query.rdf.blazegraph.filters.JWTIdentityFilter.doFilter(JWTIdentityFilter.java:66)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)\n\tat org.wikidata.query.rdf.blazegraph.filters.RealAgentFilter.doFilter(RealAgentFilter.java:33)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)\n\tat org.wikidata.query.rdf.blazegraph.filters.RequestConcurrencyFilter.doFilter(RequestConcurrencyFilter.java:50)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1340)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1242)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)\n\tat org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:220)\n\tat org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:503)\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)\n\tat org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)\n\tat org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)\n\tat org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)\n\tat org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)\n\tat java.lang.Thread.run(Thread.java:750)\nCaused by: org.openrdf.query.MalformedQueryException: Lexical error at line 58, column 5.  Encountered: " " (32), after : "%"\n\tat com.bigdata.rdf.sail.sparql.Bigdata2ASTSPARQLParser.parseQuery2(Bigdata2ASTSPARQLParser.java:404)\n\tat com.bigdata.rdf.sail.webapp.QueryServlet$SparqlQueryTask.call(QueryServlet.java:741)\n\tat com.bigdata.rdf.sail.webapp.QueryServlet$SparqlQueryTask.call(QueryServlet.java:695)\n\tat com.bigdata.rdf.task.ApiTaskForIndexManager.call(ApiTaskForIndexManager.java:68)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:266)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\n\t... 1 more\nCaused by: com.bigdata.rdf.sail.sparql.ast.TokenMgrError: Lexical error at line 58, column 5.  Encountered: " " (32), after : "%"\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilderTokenManager.getNextToken(SyntaxTreeBuilderTokenManager.java:3994)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.jj_ntk(SyntaxTreeBuilder.java:9637)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.GroupGraphPattern(SyntaxTreeBuilder.java:1963)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.GroupOrUnionGraphPattern(SyntaxTreeBuilder.java:2451)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.GraphPatternNotTriples(SyntaxTreeBuilder.java:2361)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.GraphPattern(SyntaxTreeBuilder.java:2047)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.GraphPattern(SyntaxTreeBuilder.java:2056)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.GroupGraphPattern(SyntaxTreeBuilder.java:1969)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.WhereClause(SyntaxTreeBuilder.java:1013)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.SelectQuery(SyntaxTreeBuilder.java:377)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.NamedSubquery(SyntaxTreeBuilder.java:909)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.SelectQuery(SyntaxTreeBuilder.java:375)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.Query(SyntaxTreeBuilder.java:328)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.QueryContainer(SyntaxTreeBuilder.java:216)\n\tat com.bigdata.rdf.sail.sparql.ast.SyntaxTreeBuilder.parseQuery(SyntaxTreeBuilder.java:32)\n\tat com.bigdata.rdf.sail.sparql.Bigdata2ASTSPARQLParser.parseQuery2(Bigdata2ASTSPARQLParser.java:336)\n\t... 7 more\n'