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

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

b = A("b")
j = B("j")
g = B("g")
c = B("c")
h = A("h")
f = A("f")
k = B("k")
m = A("m")

b.w = m
b.x = g
j.z = g
g.z = c
c.z = j
h.w = m
h.x = k
f.w = b
f.x = k
k.z = j
m.w = f
m.x = k
assert b.x.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.x: B = None
        self.txt = txt

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

b = A("b")
j = B("j")
g = B("g")
c = B("c")
h = A("h")
f = A("f")
k = B("k")
m = A("m")

b.w = m
b.x = g
j.z = g
g.z = c
c.z = j
h.w = m
h.x = k
f.w = b
f.x = k
k.z = j
m.w = f
m.x = k
assert b.x.z.z.z.z.z.z.txt == "g"