The SET DISPLAY MODE command will cause you a lot of problems if you don't take care. When you use it, DirectX is basically restarted (that's an oversimplification, but it'll do), which means that pretty much anything graphical will be lost and need to be reloaded. My advice is to only use the command at the beginning of your program.
The SYNC MASK command is (to be polite) a bit of a bodge, and was added to the command set relatively late. It allows you to cause the system to render to specific cameras, by specifying a binary bit mask. If you use the binary representation (which you have), then you can work out which camera will be synced with a SYNC by counting the 1's from the right-hand side.
For example %1011001 will sync cameras 0, 3, 4 and 6.
Camera 0 is special, as this will also carry out a number of other tasks (including updating the display), so generally, you will sync camera 0 last in your game loop.