aaaa, if you will find way how to put every mask element on different heights - it maybe possible to connect them by water - and you can just select water pathes to make connections from them
maybe you can do it by using huuuuuuuuuuuuge gradient node