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

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

g = A("g")
a = B("a")
f = B("f")
b = A("b")
e = B("e")

g.r = b
a.y = e
a.t = b
f.y = e
f.t = g
b.r = g
e.y = f
e.t = g
assert e.y.y.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

g = A("g")
a = B("a")
f = B("f")
b = A("b")
e = B("e")

g.r = b
a.y = e
a.t = b
f.y = e
f.t = g
b.r = g
e.y = f
e.t = g
assert e.y.y.t.txt == "g"