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

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

g = A("g")
m = B("m")
i = A("i")
b = A("b")
c = A("c")
d = A("d")
k = B("k")
n = B("n")

g.r = m
g.v = k
m.q = b
m.z = b
i.r = m
i.v = k
b.r = n
b.v = n
c.r = k
c.v = k
d.r = k
d.v = n
k.q = g
k.z = b
n.q = i
n.z = d
assert c.r.z.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.v: B = None
        self.txt = txt

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

g = A("g")
m = B("m")
i = A("i")
b = A("b")
c = A("c")
d = A("d")
k = B("k")
n = B("n")

g.r = m
g.v = k
m.q = b
m.z = b
i.r = m
i.v = k
b.r = n
b.v = n
c.r = k
c.v = k
d.r = k
d.v = n
k.q = g
k.z = b
n.q = i
n.z = d
assert c.r.z.r.q.txt == "i"