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

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

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

g = A("g")
n = B("n")
m = C("m")
h = A("h")
i = B("i")

g.o = m
g.q = i
g.r = i
n.t = g
m.y = n
m.r = n
h.o = m
h.q = i
h.r = n
i.t = h
assert i.t.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.q: B = None
        self.r: B = None
        self.txt = txt

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

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

g = A("g")
n = B("n")
m = C("m")
h = A("h")
i = B("i")

g.o = m
g.q = i
g.r = i
n.t = g
m.y = n
m.r = n
h.o = m
h.q = i
h.r = n
i.t = h
assert i.t.r.t.txt == "g"