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

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

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

b = A("b")
h = B("h")
g = C("g")
n = A("n")
f = A("f")
a = B("a")
c = B("c")

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

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

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

b = A("b")
h = B("h")
g = C("g")
n = A("n")
f = A("f")
a = B("a")
c = B("c")

b.q = c
b.o = g
h.r = g
g.v = b
g.r = b
g.z = n
n.q = h
n.o = g
f.q = a
f.o = g
a.r = g
c.r = g
assert n.q.r.z.q.r.txt == "g"