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

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

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

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

n = A("n")
i = B("i")
h = C("h")
a = D("a")
j = C("j")
f = B("f")

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

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

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

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

n = A("n")
i = B("i")
h = C("h")
a = D("a")
j = C("j")
f = B("f")

n.q = i
n.v = f
n.s = j
i.o = n
h.x = a
h.p = j
h.q = n
h.r = f
a.z = f
a.w = h
j.x = a
j.p = h
j.q = n
j.r = f
f.o = n
assert j.q.s.r.txt == "f"