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

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

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

g.x = k
c.w = g
c.v = k
k.w = g
k.v = c
assert k.w.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

g.x = k
c.w = g
c.v = k
k.w = g
k.v = c
assert k.w.x.w.txt == "g"