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

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

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

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

j.w = k
c.p = j
c.w = f
f.r = k
f.q = d
f.p = c
b.r = j
b.q = c
b.p = c
d.p = j
d.w = h
h.r = k
h.q = d
h.p = d
k.w = j
assert c.w.r.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

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

j.w = k
c.p = j
c.w = f
f.r = k
f.q = d
f.p = c
b.r = j
b.q = c
b.p = c
d.p = j
d.w = h
h.r = k
h.q = d
h.p = d
k.w = j
assert c.w.r.w.w.w.w.w.txt == "j"