Detection of Multi-TeV Gamma Rays from Markarian 501 during an Unforeseen Flaring State in 1997 with the Tibet Air Shower Array