For oropharynx primary tumors, the patient must have negative human papillomavirus (HPV) status of the tumor as determined by p16 protein expression using immunohistochemistry (IHC) Any human papillomavirus (HPV) status or smoking history is permitted; oropharyngeal cancer patients are required to undergo HPV testing with p16 immunohistochemistry and/or confirmatory HPV polymerase chain reaction (PCR) or in situ hybridization (ISH) testing Histological confirmation of human papillomavirus (HPV) positive (+) squamous cell carcinoma of the oropharynx; HPV positivity will be defined as positive staining for p16 on immunohistochemistry (IHC) Human Papillomavirus (HPV)+ disease of the oropharynx Dose expansion:\r\n* HPV-associated locally advanced or metastatic platinum-resistant solid tumor malignancy; HPV positivity defined by positive p16 immunohistochemistry, polymerase chain reaction, or in-situ hybridization assessment of archival tissue (primary or metastatic) in a Clinical Laboratory Improvement Act (CLIA)-certified laboratory; availability of pathology report from CLIA-certified lab demonstrating positive HPV status by p16 IHC, polymerase chain reaction, or in situ hybridization qualifies for eligibility determination; analysis of fresh tumor tissue is permitted in cases where archival tissue is not available\r\n* Platinum resistance defined as prior progression (radiographic or clinical) either during or within 6 months following completion of platinum-based chemotherapy\r\n* Platinum-based therapy as most recent systemic therapy prior to enrollment allowed but not required HPV-positive status ( In HNSCC patients only) Patients who are HPV-positive by deoxyribonucleic acid (DNA) test Patients with HPV-positive or p16-positive oropharyngeal squamous cell carcinoma (SCCA) Participants must have histologically or cytologically confirmed and identified resectable primary squamous cell carcinoma of the oropharynx that is HPV 16 positive or positive for any high risk HPV subtype (i.e., 18, 33, 35, etc.) as determined by PCR at the central laboratory. Patients must have p16+ status as determined by IHC performed or reviewed at the central laboratory. Both p16 and HPV status must be determined prior to post-surgical adjuvant treatment assignment. Tissue from the primary site must be available for biomarker studies after surgery p16 or HPV negative oropharyngeal squamous cell carcinoma (OPSCC) as determined by immunohistochemistry (IHC) and polymerase chain reaction (PCR), respectively Known human papillomavirus (HPV) status Patients with vulvar cancer originating from differentiated vulvar intraepithelial neoplasia (d-VIN), as opposed to vulvar intraepithelial neoplasia of usual type, are excluded; vulvar squamous cell carcinoma originating from differentiated VIN (d-VIN) is HPV negative; however, rare cases of HPV positive d-VIN can occur; patients are not excluded if their tumor has tested positive for HPV or there is no documentation of prior VIN type Diagnosis of P16/HPV-ISH positive OPSCC Have tumor tissue for PD L1 expression testing, and for oropharyngeal cancer have results from testing of HPV p16 status. All patients with oropharyngeal SCCHN must be tested for HPV (by p16 and/or HPV in situ hybridization [ISH] or polymerase chain reaction [PCR]) Tumor sample must be available for HPV p16 and PD-L1 testing and if oropharyngeal, must be tested for HPV p16 Subjects with histologically- or cytologically-documented incurable human papillomavirus (HPV)-positive OPSCC. HPV-16 serotype will be assessed by Cervista assay. Vulvar HSIL must be HPV-16+ by a polymerase chain reaction (PCR), ribonucleic acid (RNA), or in situ hybridization test from a CLIA certified laboratory Patients vulvar HSIL that is not HPV-16+ or is associated with multiple types of high-risk HPV are not eligible Low-risk HPV+ disease, defined as meeting all of the following criteria:\r\n* Patients with HPV+ by fluorescence in situ hybridization (FISH) and/or p16\r\n* Smoking history =< 10 pack years\r\n* Stage T1-2N0-2b, T3N0 HPV testing must be compliant with the following criteria:\r\n* p16 IHC positivity is sufficient to enroll and initiate treatment (p16 IHC interpretation to follow guidelines by Jordan and Lingen et al)\r\n* p16 IHC positivity is to be validated using an HPV polymerase chain reaction (PCR) during the induction phase; this is essential as HPV genotype influences treatment arm allocation, with non-HPV16 HPV strains being considered high risk Prior HPV vaccination Currently participating in an interventional research study related to HPV, except the Anal Cancer HSIL Outcomes Research (ANCHOR) study (NCT02135419) Participants must have histologically or cytologically confirmed squamous cell carcinoma of the oropharynx, hypopharynx, supraglottic larynx, nasal cavity, unknown primary, or nasopharynx that is p16 and HPV positive; tissue or cytology from the primary site or lymph node must be available for biomarker studies and for polymerase chain reaction (PCR) testing; immunohistochemistry (IHC) must be performed in a lab verified by the central laboratory or the slides must be available for review by the central laboratory (Zhang, MSSM) and PCR must be done in the central laboratory prior to radiotherapy; HPV PCR must be performed and results available for reduced dose therapy after induction.\r\n* Patients who are on the Quarterback Trial when Quarterback 2 is activated and who have been randomized to radiotherapy arm will be asked to transfer to this trial and receive the Quarterback 2 defined radiotherapy Histologically or cytologically proven HPVOC or cervical cancer or anal cancer, based on the presence of HPV type16, detected by immunohistochemistry with P16 staining followed by polymerase chain reaction (PCR) of tumor tissue from the primary or metastatic lesions Measurable metastatic or refractory/recurrent HPV-16+ cancer (determined by in situ hybridization [ISH] or a polymerase chain reaction [PCR]-based test) Histologically or cytologically confirmed HNSCC of the oral cavity (OC; more than 90% patients have HPV negative cancer) or oropharynx (about 60-80% of patient have HPV positive cancer) HPV status in oropharyngeal carcinomas; while HPV status (e.g. via p16) does not have to be known prior to consenting, the HPV status (e.g. using p16 immunohistochemistry [IHC]) needs to be established prior to start of therapy Must be considered intermediate or high risk:\r\n* Oropharynx intermediate risk patients include those who have all of the following:\r\n** Human papillomavirus (HPV)/p16 (positive [+]) disease, a significant tobacco smoking history (> 10 pack years) and N2b-N3 disease OR\r\n** HPV (negative [-]) disease, =< 10 years of smoking and large tumors (T2-T3)\r\n* Oropharynx high risk patients include those who are either:\r\n** HPV (-) with > 10 years of smoking, OR\r\n** HPV (-), =< 10 years of smoking and T4 disease\r\n* Oral cavity, larynx, hypopharynx are considered high/intermediate risk (regardless of HPV, p16 or smoking status) PROCUREMENT: Diagnosis of a cancer for which the presence of a high risk HPV type has been documented in a biopsy sample (results may be pending at this time) TREATMENT: Diagnosis of a cancer for which the presence of a high risk HPV type has been documented in a biopsy sample The patient's tumor is HPV positive by polymerase chain reaction (PCR) or in situ hybridization (ISH) assay of tumor biopsy patients whose lesions are HPV16+ Subject has pathologic confirmation of recurrent or metastatic HNSCC, regardless of human papillomavirus (HPV) status or PDL-1 status Tumor HPV status established Participants must have histologically or cytologically confirmed squamous cell carcinoma of the oropharynx or unknown primary that is high risk human papillomavirus (HPV) positive as determined by p16 immunohistochemistry (IHC) testing and/or HPV in situ hybridization (ISH) / polymerase chain reaction (PCR) Histologically or cytologically confirmed diagnosis of cervical, anal, penile, vulvar, or vaginal cancer positive for HPV-16 and/or HPV-18 by the Cervista assay. Tumors may be positive for more than 1 HPV subtype as long as HPV-16 and/or HPV-18 is present. Note: for the first 6 patients, only cervical, vulvar, or vaginal cancers will be enrolled. Known human papillomavirus (HPV) status for oropharyngeal primary tumors Tumors must be staged T1-4, N2b-3, M0 (human papillomavirus positive [HPV]+ or HPV negative [-]); patients with HPV+ tumors should have at least one high risk feature such as T4, N3, or smoking history of > 10 pack years Patients must have high or intermediate risk disease, defined as follows:\r\n* High risk: non-oropharyngeal subsite including larynx or hypopharynx (p16 status not required) or human papilloma virus (HPV)/p16- oropharynx subsite\r\n* Intermediate risk: HPV/p16+ oropharyngeal squamous cell cancer with: >= 10 pack (pk)-year (yr) smoking history and >= N2 nodal disease, or the presence of T4 tumor or N3 nodal disease, irrespective of smoking status Patients who are treatment naïve, high risk, stage IVa/IVb (all other sites) and histologically proven squamous cell carcinoma of the head and neck (SCCHN) with no definitive evidence of metastatic disease, excluding patients with oropharynx human papillomavirus (HPV)-positive tumors; in summary, those patients eligible are newly diagnosed and treatment naive: \r\n* Stage IVa-b squamous cell carcinoma other than oropharyngeal cancer (OPC), or\r\n* Oropharyngeal cancer (OPC) HPV-negative, stage IVa-b Patients who are treatment naïve, high risk, stage IVa/IVb (all other sites) histologically proven SCCHN with no definitive evidence of metastatic disease; in summary, those patients eligible are:\r\n* Stage IVa-b SCCHN other than OPC, or\r\n* OPC, HPV-negative, IVa-b, or\r\n* OPC, HPV positive, with greater than 10 pack-year smoking history and N2b-N3 disease Pretreatment tumor biopsy with sufficient tumor for HPV or p16 analysis is required; the tumor must be HPV(+) or p16(+) Documentation of results from testing of human papilloma virus (HPV) status for oropharyngeal cancer. Patients with primary oropharynx HNSCC must be HPV (-) according to local institutional definition using either p16 immunohistochemistry or HPV testing Carcinoma of the neck of unknown primary site origin (regardless of HPV/p16 status) is eligible Phase II only:\r\nArms 1 and 2: disease must be determined to be HPV-unrelated; HPV-unrelated SCCHN is defined as either p16-negative oropharyngeal squamous cell carcinoma (OPSCC) or non-OPSCC (larynx, hypopharynx, oral cavity) or p16-negative unknown primary SCC presenting with a level 2 or 3 neck node; p16 will be assessed by IHC; a specimen showing any staining will be considered p16-positive\r\nArm 3: disease must be HPV-related SCCHN (defined as OPSCC or unknown primary presenting with a neck mass that is either p16 positive or HPV in situ hybridization [ISH] or polymerase chain reaction [PCR] positive) HPV- negative SCCHN tumor as determined per institutional standard (eg, p16 IHC; multiplex nucleic acid sequence based amplification [NASBA] or other polymerase chain reaction [PCR]-based assays). Positive HIV test at screening (except in cohort 3, HPV-associated cancers) Subjects with histologically- or cytologically-documented incurable human papillomavirus (HPV)-16 positive solid tumors including oropharyngeal squamous cell carcinoma (OPSCC), cervical, vulvar, vaginal, anal, penile cancer; incurable HPV-16 solid tumors are defined as tumors which are not curable by salvage approaches including resection and/or re-irradiation; HPV-16 serotype will be assessed by Cervista assay Have results from testing of HPV status for oropharyngeal cancer Recurrent and/or metastatic HPV-related carcinoma of the cervix, anus, vagina, vulva, penis, or oropharynx; the cancer diagnosis must be confirmed by slide review in the Memorial Sloan-Kettering Cancer Center (MSKCC) Department of Pathology; HPV positive status must be demonstrated by HPV in situ-hybridization (ISH) and/or by p16 immunohistochemistry (IHC)\r\n* Note: for cervix squamous cancer, HPV ISH test or p16 IHC test is not required At least one prior systemic therapy regimen for R/M HPV-related carcinoma HPV testing must follow the following criteria\r\n* HPV testing using an E6/E7 based assay is preferred, and does not require any validation (e.g. HPV in situ hybridization [ISH] or HPV E6/E7 polymerase chain reaction [PCR])\r\n* For oropharyngeal tumors p16 immunohistochemistry (IHC) positivity is sufficient to enroll and initiate treatment (p16 IHC interpretation to follow guidelines by Jordan/Lingen et al 2012); it is recommended that p16 IHC positivity is validated at a later point (during or after treatment) using an E6/E7 based test at the University of Chicago and provided slides will be used\r\n* For non-operative (OP) tumors accurate HPV testing (i.e. ISH, or E6/E7 based testing) is required for enrollment and treatment initiation Subjects must have a histologically or cytologically confirmed metastatic or unresectable\r\n* Solid tumor (for phase I dose escalation portion), OR\r\n* virally mediated tumors (such as with HPV+ nasopharyngeal cancer, HPV+ cervical cancer) and liposarcoma (for expansion cohort) Availability of tissue for HPV testing (paraffin block or one 7-µm section on a slide). Tumor positive for infection with human papillomavirus (HPV) virus type 16 or other types such as per Johns Hopkins (JH) Pathology assessment For oropharynx or nasopharynx primary lesions, documentation of viral status is required (e.g. high risk human papilloma virus [HPV] sub-type polymerase chain reaction [PCR], p16 IHC, HPV in situ hybridization [ISH], Epstein-Barr virus-encoded small ribonucleic acid [EBER], etc); tests done on primary tumor specimens from date of initial diagnosis at outside institutions are sufficient to meet this criterion Patients must have HPV positive HNSCC containing activating PIK3CA mutations. Measurable metastatic or refractory/recurrent HPV-16+ cancer (determined by in situ hybridization [ISH] or a polymerase chain reaction [PCR]-based test) History of previous therapeutic HPV vaccination; Measurable metastatic or locally advanced refractory/recurrent malignancies that are HPV-16 or HPV-18 HPV positive by in situ hybridization (ISH) or polymerase chain reaction (PCR) or any cancer from the uterine cervix Histologically or cytologically confirmed diagnosis of HNSCC associated with HPV by a p16 immunohistochemistry (IHC) assay or HPV-16 or HPV-18 positive by nucleic acid testing. Patients must have histologically confirmed head and neck cancer (squamous cell histology), and may be poorly differentiated, stages IVA, IVB, and select cases of stage III or any stage that meets criterion\r\n* Human papilloma virus (HPV) status is required prior to randomization for oropharyngeal primary tumors, other anatomic sites will be classified as HPV- unless requested per the treating physician\r\n* Epstein Barr virus (EBV) status is required prior to randomization for nasopharyngeal primary tumors, other anatomic sites will be classified as HPV- unless requested per the treating physician Documented HPV/ EBV-positive tumor as determined by a local laboratory for Part 1B and Part 2B pembrolizumab combination viral-positive expansion cohorts only Medically indicated subunit (Engerix-B for HBV, Gardasil for HPV) or killed vaccine (e.g. influenza, pneumococcal, or allergy treatment with antigen injections) Medically indicated subunit (Engerix-B for HBV; Gardasil for human papillomavirus [HPV]) or killed vaccines (e.g. influenza, pneumococcal, or allergy treatment with antigen injections) Human papilloma virus (HPV) status in tumor has been documented using tumor immunohistochemistry for HPV-p16 or other accepted test Women who report no history of co-testing (Pap and HPV) within the last five years Previous prophylactic HPV vaccination Survey response indicated no prior history of HPV vaccination Agrees to return to participating institution for 3 HPV vaccine injections Allergy to any component of the HPV vaccine including yeast and aluminum RECIPIENT: Medically indicated subunit (Engerix?B for HBV; Gardasil for human papillomavirus [HPV]) or killed vaccines (e.g. influenza, pneumococcal, or allergy treatment with antigen injections) HPV positive by the GeneXpert hrHPV assay with HPV16, HPV 18/45, or HPV31/33/35/52/58 detected; Note: participants who are hrHPV positive with only HPV51/59 or HPV 39/68/56/66 detected are not eligible Prior HPV vaccination Primary oropharyngeal HNSCC which is HPV (+) as defined by p16 IHC Women with an abnormal pap test, positive human papillomavirus (HPV) test or any history of cervical dysplasia Has a minimum of one child between the ages of 9 and 17 who has not received the HPV vaccine and who lives with the parent/guardian as per self-report Undecided parents (18 years and older) whose children are 11-17 year old patients who have not begun the HPV vaccine series. Prior use of an HPV vaccine \r\n* Women in the vaccine-eligible age range cannot have received vaccine prior to enrollment, but will be offered HPV vaccination at the end of the study; in brief, we are interested in the efficacy of intervention in preventing HPV in the absence of HPV vaccination, since most women worldwide who might utilize intervention will not have been vaccinated; this includes United States (US) women in the vaccine “catch-up” 19-26 year old age group (beyond the age groups eligible for Vaccines for Children- funded vaccination) who have so far had very low (< 10%) vaccine uptake; it also includes the entire group of US women > 26 years of age; moreover, it includes women of all ages in developing countries, who most need an HPV prevention strategy, but may never be vaccinated; it should be noted that delaying vaccination in women 19-26 years of age by one year is safe and reasonable, since there is insufficient data to establish a recommendation for or against universal vaccination in this age group as concluded by an American Cancer Society expert panel, which includes the Principal Investigator (PI) of this protocol, Dr. Mark Einstein; it is anticipated that if the intervention gel is efficacious, HPV vaccinated women would need to be studied in a similar future trial with power analysis taking into account vaccine effectiveness as well Patients whose lesions are HPV16+ by polymerase chain reaction (PCR) (treatment groups 1, 2, 3 and 5); group 4 (imiquimod alone: 6 HPV16+ subjects, 12 HPV16- subjects) Has not received any doses of HPV vaccine Patients who have ONLY HPV 16 OR HPV 16 AND 18 and no other High-Risk HPV by Cobas test will be included. Receipt of (e.g. Gardasil® or Cervarix®) HPV preventative vaccines within 8 years of study enrollment Previous vaccination against HPV Human Papilloma Virus (HPV) status Not having received any doses of the HPV vaccine Prior receipt of Gardasil or other HPV vaccine Previous vaccination against HPV or planned administration of another HPV vaccine during the study other than that foreseen in the protocol. if they test positive for oncogenic HPV infection, but display normal cervical cytology at their concluding HPV-015 study end visit; if they are pregnant so that no cervical sample can be taken at their concluding HPV-015 study end visit; Women undergoing colposcopy for an abnormal Pap test, positive HPV test or history of cervical dysplasia (cervical intraepithelial neoplasia [CIN] or adenocarcinoma in situ [AIS]) Human papilloma virus (HPV) negative tumor for patients with oropharyngeal cancers.