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

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

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

g.v = d
k.r = g
k.t = d
d.r = g
d.t = k
assert d.r.v.t.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

g.v = d
k.r = g
k.t = d
d.r = g
d.t = k
assert d.r.v.t.txt == "k"