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

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

j = A("j")
d = B("d")
g = A("g")

j.t = d
d.v = j
g.t = d
assert d.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.v: A = None
        self.txt = txt

j = A("j")
d = B("d")
g = A("g")

j.t = d
d.v = j
g.t = d
assert d.v.t.v.txt == "j"