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

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

g = A("g")
f = B("f")
l = B("l")
i = B("i")
c = A("c")
m = A("m")
b = B("b")

g.s = m
g.w = f
f.z = g
l.z = m
i.z = g
c.s = g
c.w = l
m.s = g
m.w = i
b.z = g
assert f.z.s.w.z.w.z.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.w: B = None
        self.txt = txt

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

g = A("g")
f = B("f")
l = B("l")
i = B("i")
c = A("c")
m = A("m")
b = B("b")

g.s = m
g.w = f
f.z = g
l.z = m
i.z = g
c.s = g
c.w = l
m.s = g
m.w = i
b.z = g
assert f.z.s.w.z.w.z.txt == "g"