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

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

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

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

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

j.p = d
k.t = f
k.w = l
k.r = d
f.x = d
f.q = k
f.p = k
f.z = l
d.r = f
l.p = d
assert l.p.r.z.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

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

j.p = d
k.t = f
k.w = l
k.r = d
f.x = d
f.q = k
f.p = k
f.z = l
d.r = f
l.p = d
assert l.p.r.z.p.r.txt == "f"