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

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

i = A("i")
b = B("b")
c = A("c")
e = A("e")
g = B("g")
a = A("a")

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

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

i = A("i")
b = B("b")
c = A("c")
e = A("e")
g = B("g")
a = A("a")

i.x = a
i.w = g
b.z = g
c.x = e
c.w = g
e.x = c
e.w = b
g.z = b
a.x = c
a.w = g
assert a.x.w.z.txt == "b"