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

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

d = A("d")
f = B("f")
i = A("i")
l = B("l")
a = B("a")
e = B("e")
h = B("h")
m = B("m")

d.u = i
f.p = a
i.u = d
l.p = m
a.p = m
e.p = f
h.p = m
m.p = h
assert i.u.u.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

d = A("d")
f = B("f")
i = A("i")
l = B("l")
a = B("a")
e = B("e")
h = B("h")
m = B("m")

d.u = i
f.p = a
i.u = d
l.p = m
a.p = m
e.p = f
h.p = m
m.p = h
assert i.u.u.u.u.u.u.u.txt == "d"