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

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

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

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

c.t = k
c.x = j
g.p = e
i.p = j
i.r = n
i.t = n
k.p = c
k.r = i
k.t = d
m.p = j
n.p = j
n.r = d
n.t = d
j.t = i
j.x = e
e.t = n
e.x = c
d.p = j
d.r = n
d.t = i
assert m.p.x.x.t.p.x.t.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.x: A = None
        self.txt = txt

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

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

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

c.t = k
c.x = j
g.p = e
i.p = j
i.r = n
i.t = n
k.p = c
k.r = i
k.t = d
m.p = j
n.p = j
n.r = d
n.t = d
j.t = i
j.x = e
e.t = n
e.x = c
d.p = j
d.r = n
d.t = i
assert m.p.x.x.t.p.x.t.r.r.txt == "d"