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

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

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

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

j = A("j")
f = B("f")
n = C("n")
c = D("c")
i = C("i")
k = D("k")

j.z = f
j.w = f
j.q = k
f.p = k
f.y = j
f.v = j
f.r = j
n.s = c
c.x = n
c.v = n
c.r = k
c.q = f
i.s = k
k.x = i
k.v = i
k.r = c
k.q = f
assert n.s.x.s.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.q: D = None
        self.w: B = None
        self.txt = txt

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

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

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

j = A("j")
f = B("f")
n = C("n")
c = D("c")
i = C("i")
k = D("k")

j.z = f
j.w = f
j.q = k
f.p = k
f.y = j
f.v = j
f.r = j
n.s = c
c.x = n
c.v = n
c.r = k
c.q = f
i.s = k
k.x = i
k.v = i
k.r = c
k.q = f
assert n.s.x.s.q.p.txt == "k"