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

class B:
    def __init__(self, txt: str):
        self.r: A = None
        self.z: C = None
        self.v: A = None
        self.y: D = None
        self.txt = txt

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

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

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

j.p = k
d.r = j
d.v = j
d.z = k
d.y = i
k.s = n
i.p = f
i.q = j
i.w = n
n.p = f
n.w = f
n.q = j
f.p = i
f.w = i
f.q = j
assert d.z.s.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: A = None
        self.z: C = None
        self.v: A = None
        self.y: D = None
        self.txt = txt

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

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

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

j.p = k
d.r = j
d.v = j
d.z = k
d.y = i
k.s = n
i.p = f
i.q = j
i.w = n
n.p = f
n.w = f
n.q = j
f.p = i
f.w = i
f.q = j
assert d.z.s.w.q.txt == "j"