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

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

j = A("j")
f = B("f")
l = B("l")
m = B("m")
c = A("c")
a = A("a")

j.w = f
j.z = f
f.w = m
l.w = m
m.w = l
c.w = f
c.z = f
a.w = l
a.z = m
assert j.w.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.z: B = None
        self.txt = txt

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

j = A("j")
f = B("f")
l = B("l")
m = B("m")
c = A("c")
a = A("a")

j.w = f
j.z = f
f.w = m
l.w = m
m.w = l
c.w = f
c.z = f
a.w = l
a.z = m
assert j.w.w.w.w.w.w.txt == "m"