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

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

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

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

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

j.q = c
j.p = c
j.v = g
j.x = n
g.t = j
n.o = j
c.y = g
c.s = g
assert n.o.p.s.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.v: B = None
        self.x: C = None
        self.p: D = None
        self.txt = txt

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

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

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

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

j.q = c
j.p = c
j.v = g
j.x = n
g.t = j
n.o = j
c.y = g
c.s = g
assert n.o.p.s.t.txt == "j"