#!/usr/bin/env python

import logging
import re
import sys

from lbdoc import LineBasedDocument
from paisalib import get_docid

logging.basicConfig(level=logging.INFO)

corpus = LineBasedDocument(sys.stdin)

while corpus.current().startswith('#'):
    logging.debug('WTF')
    corpus.advance()

while not corpus.exhausted():
    docid = get_docid(corpus.current())
    logging.debug(docid)
    corpus.advance()
    content = ''
    while not corpus.current().startswith('<text '):
        if not corpus.current().startswith('</text>'):
            if '\r' in corpus.current():
                raise Exception('Line %s contains CR.' % corpus.current())
            content = content + corpus.current()
        corpus.advance()
        if corpus.exhausted():
            break
    content = content.replace('\n', '<NEWLINE>')[:-9]
    print '%s\t%s' % (docid, content.rstrip())
