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

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

h = A("h")
l = B("l")
g = B("g")
a = A("a")

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

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

h = A("h")
l = B("l")
g = B("g")
a = A("a")

h.z = g
h.w = a
l.z = a
g.z = h
a.z = g
a.w = h
assert h.z.z.w.txt == "a"