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

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

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

class D:
    def __init__(self, txt: str):
        self.o: A = None
        self.z: C = None
        self.txt = txt

k = A("k")
e = B("e")
i = C("i")
f = D("f")
b = D("b")
d = A("d")

k.p = d
k.q = d
k.r = i
k.u = e
e.w = d
i.w = d
f.o = k
f.z = i
b.o = d
b.z = i
d.p = k
d.q = k
d.r = i
d.u = e
assert k.r.w.u.w.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.r: C = None
        self.u: B = None
        self.q: A = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.o: A = None
        self.z: C = None
        self.txt = txt

k = A("k")
e = B("e")
i = C("i")
f = D("f")
b = D("b")
d = A("d")

k.p = d
k.q = d
k.r = i
k.u = e
e.w = d
i.w = d
f.o = k
f.z = i
b.o = d
b.z = i
d.p = k
d.q = k
d.r = i
d.u = e
assert k.r.w.u.w.u.w.txt == "d"