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

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

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

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

g = A("g")
c = B("c")
n = C("n")
l = D("l")

g.s = l
c.q = l
c.o = l
c.p = n
n.o = c
n.w = c
l.p = n
l.y = c
assert c.o.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

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

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

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

g = A("g")
c = B("c")
n = C("n")
l = D("l")

g.s = l
c.q = l
c.o = l
c.p = n
n.o = c
n.w = c
l.p = n
l.y = c
assert c.o.y.p.txt == "n"