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

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

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

c = A("c")
n = B("n")
g = C("g")
m = A("m")
e = C("e")
f = A("f")

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

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

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

c = A("c")
n = B("n")
g = C("g")
m = A("m")
e = C("e")
f = A("f")

c.t = n
c.y = e
c.p = m
n.q = g
g.t = f
m.t = n
m.y = g
m.p = f
e.t = c
f.t = n
f.y = g
f.p = c
assert g.t.p.p.t.q.t.txt == "f"