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

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

c = A("c")
m = B("m")
h = B("h")
i = A("i")
f = A("f")
j = A("j")
a = B("a")
d = B("d")

c.s = f
m.q = d
m.w = j
h.q = a
h.w = i
i.s = c
f.s = c
j.s = c
a.q = d
a.w = f
d.q = m
d.w = j
assert m.w.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

c = A("c")
m = B("m")
h = B("h")
i = A("i")
f = A("f")
j = A("j")
a = B("a")
d = B("d")

c.s = f
m.q = d
m.w = j
h.q = a
h.w = i
i.s = c
f.s = c
j.s = c
a.q = d
a.w = f
d.q = m
d.w = j
assert m.w.s.s.s.s.txt == "f"