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

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

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

h = A("h")
k = B("k")
e = C("e")
g = B("g")
m = A("m")

h.q = g
k.t = g
k.o = m
k.r = e
e.p = g
g.t = k
g.o = m
g.r = e
m.q = g
assert k.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

h = A("h")
k = B("k")
e = C("e")
g = B("g")
m = A("m")

h.q = g
k.t = g
k.o = m
k.r = e
e.p = g
g.t = k
g.o = m
g.r = e
m.q = g
assert k.t.t.t.txt == "g"