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

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

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

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

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

l.q = j
f.o = k
k.q = l
j.v = k
j.o = f
j.t = l
d.v = k
d.o = f
d.t = l
assert d.o.o.q.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

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

l.q = j
f.o = k
k.q = l
j.v = k
j.o = f
j.t = l
d.v = k
d.o = f
d.t = l
assert d.o.o.q.q.t.txt == "l"