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

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

m = A("m")
i = B("i")
b = B("b")
j = B("j")
g = A("g")
l = A("l")

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

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

m = A("m")
i = B("i")
b = B("b")
j = B("j")
g = A("g")
l = A("l")

m.x = i
m.r = i
i.t = b
b.t = i
j.t = i
g.x = b
g.r = i
l.x = b
l.r = i
assert g.x.t.t.t.txt == "i"