Assuming XYZ is the path to the root of your files, you can use globbing to exactly match the files you need:
chmod 777 /XYZ/{ABCD,EGF,GHY}
You can then use the -R flag to do this recursively in all files and folders contained in these folders.
chmod -R 777 /XYZ/{ABCD,EGF,GHY}
To apply non-recursive chmod in folder 3 plus the parent element, you can use:
chmod 777 /XYZ/{ABCD,EGF,GHY,}
Pay attention to the last comma to include the directory itself in globbing
source share