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

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

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

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

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

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

i.p = n
i.u = n
d.y = k
n.p = i
n.u = i
m.y = n
k.p = i
k.u = i
e.y = n
assert m.y.p.u.p.p.txt == "n"