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

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

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

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

b = A("b")
k = B("k")
i = C("i")
c = D("c")
h = A("h")
f = C("f")
a = D("a")
l = A("l")

b.p = a
k.w = i
i.x = c
c.r = l
c.q = a
h.p = c
f.x = c
a.r = b
a.q = c
l.p = c
assert h.p.r.p.q.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

b = A("b")
k = B("k")
i = C("i")
c = D("c")
h = A("h")
f = C("f")
a = D("a")
l = A("l")

b.p = a
k.w = i
i.x = c
c.r = l
c.q = a
h.p = c
f.x = c
a.r = b
a.q = c
l.p = c
assert h.p.r.p.q.r.p.txt == "a"