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

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

f = A("f")
h = B("h")
b = A("b")
i = A("i")
e = A("e")
m = A("m")
g = A("g")
k = A("k")

f.w = b
f.y = h
h.z = g
b.w = i
b.y = h
i.w = g
i.y = h
e.w = f
e.y = h
m.w = f
m.y = h
g.w = b
g.y = h
k.w = m
k.y = h
assert b.w.w.w.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.y: B = None
        self.txt = txt

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

f = A("f")
h = B("h")
b = A("b")
i = A("i")
e = A("e")
m = A("m")
g = A("g")
k = A("k")

f.w = b
f.y = h
h.z = g
b.w = i
b.y = h
i.w = g
i.y = h
e.w = f
e.y = h
m.w = f
m.y = h
g.w = b
g.y = h
k.w = m
k.y = h
assert b.w.w.w.y.z.txt == "g"