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

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

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

j = A("j")
i = B("i")
b = C("b")
g = C("g")
n = A("n")

j.q = b
i.r = j
i.y = b
b.r = i
b.o = i
b.x = i
g.r = i
g.o = i
g.x = i
n.q = g
assert i.y.o.r.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

j = A("j")
i = B("i")
b = C("b")
g = C("g")
n = A("n")

j.q = b
i.r = j
i.y = b
b.r = i
b.o = i
b.x = i
g.r = i
g.o = i
g.x = i
n.q = g
assert i.y.o.r.q.x.txt == "i"