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

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

k = A("k")
l = B("l")
h = A("h")
d = A("d")
c = A("c")
g = B("g")

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

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

k = A("k")
l = B("l")
h = A("h")
d = A("d")
c = A("c")
g = B("g")

k.z = c
k.s = h
l.w = c
h.z = d
h.s = d
d.z = c
d.s = h
c.z = h
c.s = d
g.w = h
assert k.z.s.s.z.txt == "d"