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

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

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

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

d = A("d")
b = B("b")
l = C("l")
j = D("j")

d.o = j
b.q = l
l.p = b
l.t = b
l.o = b
l.q = d
j.u = d
j.w = b
j.p = l
j.y = l
assert d.o.u.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.txt = txt

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

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

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

d = A("d")
b = B("b")
l = C("l")
j = D("j")

d.o = j
b.q = l
l.p = b
l.t = b
l.o = b
l.q = d
j.u = d
j.w = b
j.p = l
j.y = l
assert d.o.u.o.txt == "j"