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

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

b = A("b")
g = B("g")
h = B("h")
m = B("m")
n = B("n")
k = B("k")
f = B("f")
j = A("j")

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

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

b = A("b")
g = B("g")
h = B("h")
m = B("m")
n = B("n")
k = B("k")
f = B("f")
j = A("j")

b.y = j
g.z = j
g.s = f
h.z = b
h.s = k
m.z = b
m.s = f
n.z = j
n.s = f
k.z = j
k.s = n
f.z = j
f.s = n
j.y = b
assert m.s.s.z.y.y.txt == "j"