mod_rewrite to move folders out of parent folder up to the root

On a wordpress site, I’m trying to move five subfolders and all their contents (about eighty pages in all) up one level in the tree, so that each subfolder becomes a folder off the root.

from this:
example.com/folderA/folderX/samplepage1
example.com/folderA/folderX/samplepage2
example.com/folderA/folderX/samplepage3

example.com/folderA/folderY/samplepage10
example.com/folderA/folderY/samplepage11
example.com/folderA/folderY/samplepage12
etc…

to this:

example.com/folderX/samplepage1
example.com/folderX/samplepage2
example.com/folderX/samplepage3

example.com/folderY/samplepage10
example.com/folderY/samplepage11
example.com/folderY/samplepage12
etc…

That is, eliminating the folderA parent folder altogether.

I tried recreating a test subfolder as a folder off the root and moving a page there, then using a redirect, but that 404’d. A WP plugin forum told me it needs to be done as a rewrite. I searched here and found answers to use powershell to move folders out of parent folders up to the root, but my issue is for wordpress on apache, so I am trying to find the regex to do this in the htaccess file.

Thanks in advance for any insight or help with this.