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

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

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

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

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

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

g.w = k
g.p = l
l.z = g
l.u = f
f.z = m
f.u = l
m.w = k
m.p = f
h.w = k
h.p = f
i.w = g
i.p = f
k.w = h
k.p = l
assert i.p.u.z.p.txt == "l"