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

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

d = A("d")
l = B("l")
m = A("m")
b = A("b")
f = A("f")
j = B("j")
h = A("h")
k = A("k")
c = A("c")

d.s = h
l.w = d
l.q = c
m.s = h
b.s = f
f.s = h
j.w = h
j.q = m
h.s = c
k.s = b
c.s = k
assert f.s.s.s.s.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.w: A = None
        self.q: A = None
        self.txt = txt

d = A("d")
l = B("l")
m = A("m")
b = A("b")
f = A("f")
j = B("j")
h = A("h")
k = A("k")
c = A("c")

d.s = h
l.w = d
l.q = c
m.s = h
b.s = f
f.s = h
j.w = h
j.q = m
h.s = c
k.s = b
c.s = k
assert f.s.s.s.s.s.s.s.s.txt == "k"