class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: D = None
        self.y: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

j = A("j")
i = B("i")
f = C("f")
m = D("m")
k = C("k")

j.q = i
j.s = m
j.y = k
i.x = m
f.p = k
m.q = k
k.p = f
assert f.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: D = None
        self.y: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

j = A("j")
i = B("i")
f = C("f")
m = D("m")
k = C("k")

j.q = i
j.s = m
j.y = k
i.x = m
f.p = k
m.q = k
k.p = f
assert f.p.p.p.p.p.txt == "k"