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

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

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

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

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

d.q = c
d.s = h
a.z = b
b.q = f
b.r = a
n.y = a
n.r = d
m.y = a
m.r = i
h.z = f
c.q = f
c.r = a
f.q = c
f.r = a
i.q = c
i.s = a
g.y = a
g.r = i
assert a.z.r.z.q.r.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.s: B = None
        self.txt = txt

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

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

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

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

d.q = c
d.s = h
a.z = b
b.q = f
b.r = a
n.y = a
n.r = d
m.y = a
m.r = i
h.z = f
c.q = f
c.r = a
f.q = c
f.r = a
i.q = c
i.s = a
g.y = a
g.r = i
assert a.z.r.z.q.r.z.q.txt == "f"