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

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

d = A("d")
n = B("n")
i = A("i")
g = B("g")
c = A("c")
f = B("f")
a = A("a")
b = A("b")

d.r = a
d.z = a
n.q = a
n.x = f
i.r = a
i.z = c
g.q = a
g.x = n
c.r = a
c.z = d
f.q = b
f.x = g
a.r = i
a.z = d
b.r = c
b.z = d
assert c.z.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.z: A = None
        self.txt = txt

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

d = A("d")
n = B("n")
i = A("i")
g = B("g")
c = A("c")
f = B("f")
a = A("a")
b = A("b")

d.r = a
d.z = a
n.q = a
n.x = f
i.r = a
i.z = c
g.q = a
g.x = n
c.r = a
c.z = d
f.q = b
f.x = g
a.r = i
a.z = d
b.r = c
b.z = d
assert c.z.z.r.txt == "i"