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

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

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

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

a = A("a")
d = B("d")
m = C("m")
k = D("k")
c = B("c")
b = A("b")

a.p = k
d.x = k
d.w = c
d.v = b
m.s = a
m.p = a
k.o = m
k.p = m
k.z = d
k.q = d
c.x = k
c.w = d
c.v = a
b.p = k
assert a.p.o.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

a = A("a")
d = B("d")
m = C("m")
k = D("k")
c = B("c")
b = A("b")

a.p = k
d.x = k
d.w = c
d.v = b
m.s = a
m.p = a
k.o = m
k.p = m
k.z = d
k.q = d
c.x = k
c.w = d
c.v = a
b.p = k
assert a.p.o.s.txt == "a"