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

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

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

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

d = A("d")
k = B("k")
e = C("e")
f = D("f")
c = D("c")

d.p = e
k.o = c
e.x = d
e.v = c
f.q = c
f.v = e
c.q = f
c.v = e
assert c.v.v.q.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

d = A("d")
k = B("k")
e = C("e")
f = D("f")
c = D("c")

d.p = e
k.o = c
e.x = d
e.v = c
f.q = c
f.v = e
c.q = f
c.v = e
assert c.v.v.q.q.v.txt == "e"