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

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

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

j.v = g
m.z = j
m.w = g
g.v = j
assert g.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

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

j.v = g
m.z = j
m.w = g
g.v = j
assert g.v.v.v.txt == "j"