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

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

a = A("a")
m = B("m")
i = A("i")
l = A("l")
g = B("g")
j = B("j")
c = B("c")

a.r = c
a.u = j
m.t = a
i.r = m
i.u = m
l.r = g
l.u = g
g.t = a
j.t = l
c.t = l
assert l.r.t.r.t.r.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.u: B = None
        self.txt = txt

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

a = A("a")
m = B("m")
i = A("i")
l = A("l")
g = B("g")
j = B("j")
c = B("c")

a.r = c
a.u = j
m.t = a
i.r = m
i.u = m
l.r = g
l.u = g
g.t = a
j.t = l
c.t = l
assert l.r.t.r.t.r.t.r.txt == "c"