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

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

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

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

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

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

a.t = e
g.y = e
g.v = a
e.y = g
e.v = a
assert g.v.t.v.txt == "a"