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.x: A = None
        self.txt = txt

j = A("j")
b = B("b")
m = A("m")
h = A("h")
d = B("d")
c = A("c")
n = A("n")

j.s = h
j.z = d
b.x = h
m.s = c
m.z = b
h.s = c
h.z = b
d.x = c
c.s = h
c.z = d
n.s = m
n.z = d
assert m.s.z.x.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.x: A = None
        self.txt = txt

j = A("j")
b = B("b")
m = A("m")
h = A("h")
d = B("d")
c = A("c")
n = A("n")

j.s = h
j.z = d
b.x = h
m.s = c
m.z = b
h.s = c
h.z = b
d.x = c
c.s = h
c.z = d
n.s = m
n.z = d
assert m.s.z.x.txt == "c"