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

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

b = A("b")
n = B("n")
f = A("f")
g = A("g")
d = A("d")
j = A("j")
h = A("h")
k = B("k")
c = B("c")
l = A("l")

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

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

b = A("b")
n = B("n")
f = A("f")
g = A("g")
d = A("d")
j = A("j")
h = A("h")
k = B("k")
c = B("c")
l = A("l")

b.s = j
b.z = n
n.s = f
f.s = h
f.z = n
g.s = j
g.z = c
d.s = g
d.z = n
j.s = g
j.z = c
h.s = j
h.z = c
k.s = l
c.s = d
l.s = f
l.z = k
assert f.s.s.s.s.txt == "j"