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

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

c = A("c")
a = B("a")
b = B("b")
g = B("g")

c.t = g
a.x = b
a.t = c
b.x = a
b.t = c
g.x = a
g.t = c
assert g.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

c = A("c")
a = B("a")
b = B("b")
g = B("g")

c.t = g
a.x = b
a.t = c
b.x = a
b.t = c
g.x = a
g.t = c
assert g.t.t.t.txt == "c"