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

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

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

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

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

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

a.t = e
g.r = a
g.o = e
e.t = a
assert g.o.t.t.txt == "e"