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

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

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

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

l = A("l")
a = B("a")
j = C("j")
f = D("f")
c = C("c")

l.o = f
a.w = f
a.y = f
a.p = c
a.q = j
j.r = c
f.s = c
f.t = l
f.o = l
c.r = j
assert l.o.o.o.t.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.txt = txt

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

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

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

l = A("l")
a = B("a")
j = C("j")
f = D("f")
c = C("c")

l.o = f
a.w = f
a.y = f
a.p = c
a.q = j
j.r = c
f.s = c
f.t = l
f.o = l
c.r = j
assert l.o.o.o.t.o.txt == "f"