class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.y: C = None
        self.z: C = None
        self.txt = txt

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

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

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

a = A("a")
k = B("k")
n = C("n")
m = D("m")
j = D("j")
f = D("f")

a.x = k
a.y = n
a.z = n
k.q = a
k.p = a
n.o = f
n.v = m
n.z = j
m.o = a
m.w = k
j.o = a
j.w = k
f.o = a
f.w = k
assert a.y.z.o.y.v.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.y: C = None
        self.z: C = None
        self.txt = txt

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

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

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

a = A("a")
k = B("k")
n = C("n")
m = D("m")
j = D("j")
f = D("f")

a.x = k
a.y = n
a.z = n
k.q = a
k.p = a
n.o = f
n.v = m
n.z = j
m.o = a
m.w = k
j.o = a
j.w = k
f.o = a
f.w = k
assert a.y.z.o.y.v.w.txt == "k"