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

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

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

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

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

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

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

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

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

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

a.q = k
d.z = m
d.v = j
f.p = j
f.z = d
f.r = a
k.s = f
k.o = c
m.s = f
m.o = c
c.z = k
c.v = f
j.p = f
j.z = d
j.r = a
assert c.v.z.v.p.txt == "f"