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

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

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

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

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

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

j.p = f
j.s = c
f.q = m
f.z = k
k.q = f
k.z = m
l.q = k
l.z = k
b.q = f
b.z = m
m.q = f
m.z = b
d.p = f
d.s = c
c.p = m
c.s = d
assert k.q.z.z.z.txt == "b"