Unless something else is going on that you've left out, you simply click and hold on the icon in the Dock, or the name of the app in the menubar, and select quit from the menu that appears.
Now, if you already know that, which you probably do, and they still won't quit, go to the Apple menu and select force quit. Now, if you've already tried that, open Activity Monitor in Utilities, select the process, in this case Firefox or Safari, and select Quit Process from there.
But needing to force quit or quit from Activity Monitor shouldn't be happening and we'd need to find out why.