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

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

c = A("c")
d = B("d")
m = B("m")
g = B("g")

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

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

c = A("c")
d = B("d")
m = B("m")
g = B("g")

c.x = g
d.w = g
d.v = c
m.w = d
m.v = c
g.w = d
g.v = c
assert c.x.v.x.txt == "g"