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

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

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

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

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

b.o = a
b.q = a
b.r = i
i.t = a
i.v = k
k.r = a
k.o = a
a.p = k
d.o = a
d.q = a
d.r = i
assert i.v.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.r: B = None
        self.q: D = None
        self.txt = txt

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

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

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

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

b.o = a
b.q = a
b.r = i
i.t = a
i.v = k
k.r = a
k.o = a
a.p = k
d.o = a
d.q = a
d.r = i
assert i.v.o.p.txt == "k"