#  TC/SD_Q1 Return the entry that has matching headword (``the").

for $ent in input()/dictionary/e
where $ent/hwg/hw="the"
return
    $ent


# TC/SD_Q2 Find the headword of the entry which has matching quotation year (1900).

for $ent in input()/dictionary/e
where $ent/ss/s/qp/q/qd="1900"
return
    $ent/hwg/hw


# TC/SD_Q3 Group entries by quotation location in a certain quotation year (1900) and calculate the total number entries in each group.

for $a in distinct-values
    (input()/dictionary/e/ss/s/qp/q[qd="1900"]/loc)
let $b := input()/dictionary/e/ss/s/qp/q[loc=$a]
return
    <Output>
        <Location>{$a/text()}</Location>
        <NumberOfEntries>{count($b)}</NumberOfEntries>
    </Output>

# TC/SD_Q4 List the headword of the previous entry of a matching headword (``you").

let $ent := input()/dictionary/e[hwg/hw="you"]
for $prevEnt in input()/dictionary/e[hwg/hw << $ent]
    [position() = last()]
return
    <Output>
        <CurrentEntry>{$ent/hwg/hw/text()}</CurrentEntry>
        <PreviousEntry>{$prevEnt/hwg/hw/text()}</PreviousEntry>
    </Output>

# TC/SD_Q5 Return the first sense of a matching headword (``that").

for $a in input()/dictionary/e
where $a/hwg/hw="that"
return
    $a/ss/s[1]


# TC/SD_Q6 Return the words where some quotations were quoted in a certain year (1900).

for $word in input()/dictionary/e
where some $item in $word/ss/s/qp/q
    satisfies $item/qd eq "1900"
return
    $word


# TC/SD_Q7 Return the words where all quotations were quoted in a certain year (1900).

for $word in input()/dictionary/e
where every $item in $word/ss/s/qp/q
    satisfies $item/qd eq "1900"
return
    $word


# TC/SD_Q8 Return Quotation Text (one element name unknown) of a word (``and").

for $ent in input()/dictionary/e
where $ent/*/hw = "and"
return
    $ent/ss/s/qp/*/qt


# TC/SD_Q9 Return Quotation Text (several consecutive element names unknown) of a word (``and").

for $ent in input()/dictionary/e
where $ent//hw = "or"
return
    $ent//qt


# TC/SD_Q10 List the words and their pronunciation, alphabetically, quoted in a certain year (1900).

for $a in input()/dictionary/e
where $a/ss/s/qp/q/qd = "1900"
order by $a/hwg/hw
return
    <Output>
        {$a/hwg/hw}
        {$a/hwg/pr}
    </Output>

# TC/SD_Q11 List the quotation locations and quotation dates, sorted by date, for a word (``word").

for $a in input()/dictionary/e
    [hwg/hw="the"]/ss/s/qp/q
order by $a/qd
return
    <Output>
        {$a/a}
        {$a/qd}
    </Output>

# TC/SD_Q12 Retrieve the senses of a word (``his").

for $a in input()/dictionary/e
where $a/hwg/hw="his"
return
    <Entry>
        {$a/ss}
    </Entry>

# TC/SD_Q13 Construct a brief information on a word (``his"), including: headword, pronunciation, part_of_speech, first etymology and first sense definition.

for $a in input()/dictionary/e
where $a/hwg/hw="his"
return
    <Output>
        {$a/hwg/hw}
        {$a/hwg/pr}
        {$a/hwg/pos}
        {$a/etymology/cr[1]}
        {$a/ss/s[1]/def}
    </Output>

# TC/SD_Q14 List the ids of entries that do not have variant form lists and etymologies.

for $a in input()/dictionary/e
where empty($a/vfl) and empty($a/et)
return
    <NoVFLnET>
        {$a/@id}
    </NoVFLnET>

# TC/SD_Q17 Return the headwords of the entries which contain a certain word (``hockey").

for $a in input()/dictionary/e
where contains ($a, "hockey")
return
    $a/hwg/hw


# TC/SD_Q18 List the headwords of entries which contain a given phrase (``the hockey").

for $a in input()/dictionary/e
where contains($a, "the hockey")
return
    $a/hwg/hw


# TC/SD_Q19 Retrieve the headwords of entries cited, in etymology part, by certain entry with id attribute value (E1).

for $ent in input()/dictionary/e[@id="E1"],
    $related in input()/dictionary/e
where $ent/et/cr = $related/@id
return
    <Output>
        {$related/hwg/hw}
    </Output>

