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

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

m = A("m")
k = B("k")
a = A("a")
j = B("j")
n = B("n")
c = B("c")
f = A("f")
l = A("l")
b = B("b")

m.p = a
m.z = c
k.z = n
a.p = l
a.z = b
j.z = c
n.z = k
c.z = n
f.p = a
f.z = c
l.p = f
l.z = n
b.z = j
assert f.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.z: B = None
        self.txt = txt

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

m = A("m")
k = B("k")
a = A("a")
j = B("j")
n = B("n")
c = B("c")
f = A("f")
l = A("l")
b = B("b")

m.p = a
m.z = c
k.z = n
a.p = l
a.z = b
j.z = c
n.z = k
c.z = n
f.p = a
f.z = c
l.p = f
l.z = n
b.z = j
assert f.z.z.z.txt == "k"