Used as a humorously euphemistic substitute for a four-letter swear word (usually ‘fuck’) in "not to give a XXXX" and variants: not to care at all, not to give a damn.
The phrase originated in a series of British television advertisements for Castlemaine XXXX lager.
1980s; earliest use found in The Sunday Times. From the trademark Castlemaine XXXX, a brand of Australian lager (with letter X reduplicated to designate the relative strength of beer, stout, etc.), punningly after the use of X to replace an unknown or suppressed name, number, etc.