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

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

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

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

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

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

m.v = g
h.v = g
h.z = g
g.v = h
g.z = h
assert h.v.z.z.txt == "g"