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

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

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

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

g.r = b
h.o = e
h.q = n
h.x = n
n.x = f
e.o = m
e.q = b
e.x = b
m.o = h
m.q = b
m.x = n
f.r = n
a.r = n
b.x = g
assert a.r.x.r.x.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

g.r = b
h.o = e
h.q = n
h.x = n
n.x = f
e.o = m
e.q = b
e.x = b
m.o = h
m.q = b
m.x = n
f.r = n
a.r = n
b.x = g
assert a.r.x.r.x.r.x.txt == "f"