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

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

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

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

n = A("n")
d = B("d")
g = C("g")
c = D("c")
m = A("m")
j = B("j")
a = D("a")
h = A("h")
b = C("b")
i = D("i")

n.r = a
n.q = b
d.r = j
g.v = h
c.s = d
c.p = b
c.x = g
c.z = j
m.r = a
m.q = b
j.r = d
a.s = j
a.z = j
a.p = g
a.x = g
h.r = c
h.q = b
b.v = h
i.s = j
i.z = j
i.p = g
i.x = b
assert n.q.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.q: C = None
        self.txt = txt

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

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

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

n = A("n")
d = B("d")
g = C("g")
c = D("c")
m = A("m")
j = B("j")
a = D("a")
h = A("h")
b = C("b")
i = D("i")

n.r = a
n.q = b
d.r = j
g.v = h
c.s = d
c.p = b
c.x = g
c.z = j
m.r = a
m.q = b
j.r = d
a.s = j
a.z = j
a.p = g
a.x = g
h.r = c
h.q = b
b.v = h
i.s = j
i.z = j
i.p = g
i.x = b
assert n.q.v.r.txt == "c"