class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.u: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

i = A("i")
n = B("n")
d = A("d")
h = A("h")
m = A("m")
k = B("k")

i.x = n
i.u = k
n.p = k
d.x = n
d.u = k
h.x = n
h.u = k
m.x = k
m.u = n
k.p = n
assert i.x.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.u: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

i = A("i")
n = B("n")
d = A("d")
h = A("h")
m = A("m")
k = B("k")

i.x = n
i.u = k
n.p = k
d.x = n
d.u = k
h.x = n
h.u = k
m.x = k
m.u = n
k.p = n
assert i.x.p.p.p.p.txt == "n"