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

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

m = A("m")
l = B("l")
c = B("c")
f = A("f")
g = A("g")
e = B("e")

m.t = l
m.y = l
l.r = m
c.r = f
f.t = l
f.y = c
g.t = e
g.y = e
e.r = g
assert m.y.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.y: B = None
        self.txt = txt

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

m = A("m")
l = B("l")
c = B("c")
f = A("f")
g = A("g")
e = B("e")

m.t = l
m.y = l
l.r = m
c.r = f
f.t = l
f.y = c
g.t = e
g.y = e
e.r = g
assert m.y.r.t.txt == "l"