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

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

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

g = A("g")
n = B("n")
c = C("c")
i = B("i")
f = C("f")
d = C("d")
l = B("l")
j = A("j")

g.p = j
g.r = j
n.s = j
n.t = d
c.r = g
i.s = j
i.t = f
f.r = g
d.r = j
l.s = j
l.t = d
j.p = g
j.r = g
assert n.s.p.r.r.r.p.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.r: A = None
        self.txt = txt

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

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

g = A("g")
n = B("n")
c = C("c")
i = B("i")
f = C("f")
d = C("d")
l = B("l")
j = A("j")

g.p = j
g.r = j
n.s = j
n.t = d
c.r = g
i.s = j
i.t = f
f.r = g
d.r = j
l.s = j
l.t = d
j.p = g
j.r = g
assert n.s.p.r.r.r.p.r.p.txt == "g"