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

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

a = A("a")
l = B("l")
i = B("i")
g = B("g")
j = B("j")
k = B("k")
h = A("h")
m = A("m")
f = B("f")

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

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

a = A("a")
l = B("l")
i = B("i")
g = B("g")
j = B("j")
k = B("k")
h = A("h")
m = A("m")
f = B("f")

a.w = g
a.x = m
l.z = g
i.z = l
g.z = k
j.z = l
k.z = f
h.w = g
h.x = a
m.w = k
m.x = h
f.z = l
assert k.z.z.z.z.z.z.z.txt == "g"