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

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

g = A("g")
d = B("d")
h = A("h")
f = A("f")
c = A("c")
m = B("m")
a = B("a")
i = A("i")
n = A("n")

g.u = m
d.r = h
h.u = m
f.u = d
c.u = d
m.r = c
a.r = c
i.u = m
n.u = m
assert c.u.r.u.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

g = A("g")
d = B("d")
h = A("h")
f = A("f")
c = A("c")
m = B("m")
a = B("a")
i = A("i")
n = A("n")

g.u = m
d.r = h
h.u = m
f.u = d
c.u = d
m.r = c
a.r = c
i.u = m
n.u = m
assert c.u.r.u.r.u.txt == "d"