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

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

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

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

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

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

b.z = g
b.w = g
a.x = g
a.q = h
h.z = a
h.w = g
g.x = a
g.q = h
assert b.w.x.x.txt == "g"