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

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

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

e = A("e")
m = B("m")
a = C("a")
c = C("c")
g = A("g")
h = B("h")

e.q = c
m.p = a
a.y = c
a.q = g
c.y = a
c.q = g
g.q = c
h.p = c
assert m.p.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

e = A("e")
m = B("m")
a = C("a")
c = C("c")
g = A("g")
h = B("h")

e.q = c
m.p = a
a.y = c
a.q = g
c.y = a
c.q = g
g.q = c
h.p = c
assert m.p.q.q.txt == "c"