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

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

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

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

d = A("d")
f = B("f")
k = C("k")
a = D("a")

d.y = k
d.o = f
d.r = a
f.p = a
k.p = f
a.q = f
a.y = f
a.u = d
a.p = d
assert k.p.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.o: B = None
        self.r: D = None
        self.txt = txt

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

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

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

d = A("d")
f = B("f")
k = C("k")
a = D("a")

d.y = k
d.o = f
d.r = a
f.p = a
k.p = f
a.q = f
a.y = f
a.u = d
a.p = d
assert k.p.p.q.txt == "f"