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

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

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

m = A("m")
d = B("d")
i = C("i")
n = B("n")
g = C("g")
j = A("j")

m.t = d
m.r = n
m.y = j
d.o = i
d.r = i
i.r = j
i.p = g
i.w = d
n.o = i
n.r = i
g.r = m
g.p = i
g.w = n
j.t = n
j.r = n
j.y = m
assert m.t.o.w.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.r: B = None
        self.y: A = None
        self.txt = txt

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

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

m = A("m")
d = B("d")
i = C("i")
n = B("n")
g = C("g")
j = A("j")

m.t = d
m.r = n
m.y = j
d.o = i
d.r = i
i.r = j
i.p = g
i.w = d
n.o = i
n.r = i
g.r = m
g.p = i
g.w = n
j.t = n
j.r = n
j.y = m
assert m.t.o.w.o.p.txt == "g"