Kinfolk

Given two positions in a binary family tree and the second person's gender, print the English kinship term of the second to the first.

Medium5TreeMathImplementationNo attempts yetTime limit1sMemory limit256 MB

Problem

English has a large vocabulary for family relationships. The base relationships are:

  • self, parent (mother and father), and child (daughter and son).
  • Another child of your parent is your sister if female, your brother if male.
  • The child of your sister or brother is your niece if female, your nephew if male. You are their aunt if female, their uncle if male.
  • Two people who share a grandparent but not a parent are 1st cousins. If they share a great-grandparent but not a grandparent, they are 2nd cousins. The same rule gives 3rd cousins and beyond.

Later generations use these extensions:

  • daughter, son, niece and nephew extend downward with the prefixes "grand", "great-grand" and "great-great-grand". The son of your son or daughter is a grandson. The son of your niece or nephew is your grandnephew, and your grandnephew's daughter is your great-grandniece. In theory any number of extra "great-" prefixes is possible, but this problem stops at "great-great-grand".
  • mother, father, aunt and uncle take the same prefix symmetrically. You are the grandmother or grandfather of your granddaughter or grandson, and the great-grandaunt or great-granduncle of your great-grandnieces and great-grandnephews.
  • The cousin relationship extends to a cousin's descendants by degrees of removal. The children of your 1st cousin are your 1st cousins once removed, and you are theirs. The grandchildren of your 3rd cousin are your 3rd cousins twice removed. The great-grandchildren of your 2nd cousin are your 2nd cousins thrice removed. Every cousin relationship is symmetric, so if someone is your Kth cousin some number of times removed, you are theirs as well.

Write a program that reports the relationship of one person to another.

Input

The input holds one or more datasets. Each dataset is one line with two integers AA and BB (0A,B327670 \le A, B \le 32767) and one character. A line whose first integer is negative marks the end of the input. That line is not a dataset and produces no output.

The two integers identify person AA and person BB. The character is M or F and gives the gender of person BB, male or female.

The integers are positions in a family tree drawn as a full binary tree. The root is numbered 0, its children are numbered 1 and 2, the children of 1 are 3 and 4, the children of 2 are 5 and 6, and the numbering continues level by level, left to right. The diagram below shows the numbering. A parent-child link in this tree is a parent-child link in the family.

Output

For each dataset print one line with the relationship of BB to AA. Build the answer only from these phrases: "self", "sister", "brother", "daughter", "son", "mother", "father", "niece", "nephew", "aunt", "uncle", "cousin", "grand", "great-", "1st", "2nd", "3rd", "once removed", "twice removed", "thrice removed". At most two "great-" prefixes may be applied. If "1st", "2nd" or "3rd" is used, a single blank separates it from the rest of the line. If "once removed", "twice removed" or "thrice removed" is used, a single blank separates it from the part before it. If the relationship of BB to AA cannot be written under these limits, print "kin".