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

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

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

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

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

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

d.u = k
d.r = c
c.p = m
h.p = e
f.u = i
f.r = m
m.p = c
i.u = l
i.r = h
e.p = m
l.u = f
l.r = h
k.u = i
k.r = e
assert i.u.u.r.p.p.txt == "m"