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

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

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

d = A("d")
f = B("f")
j = C("j")
l = C("l")
g = C("g")
m = C("m")
n = C("n")
c = B("c")
h = A("h")
e = B("e")

d.r = f
d.x = h
f.w = c
f.p = c
f.q = n
j.t = e
j.x = f
j.p = h
l.t = e
l.x = c
l.p = d
g.t = f
g.x = f
g.p = d
m.t = f
m.x = f
m.p = d
n.t = f
n.x = f
n.p = d
c.w = e
c.p = e
c.q = g
h.r = f
h.x = d
e.w = c
e.p = c
e.q = j
assert d.x.r.q.p.x.r.w.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.x: A = None
        self.txt = txt

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

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

d = A("d")
f = B("f")
j = C("j")
l = C("l")
g = C("g")
m = C("m")
n = C("n")
c = B("c")
h = A("h")
e = B("e")

d.r = f
d.x = h
f.w = c
f.p = c
f.q = n
j.t = e
j.x = f
j.p = h
l.t = e
l.x = c
l.p = d
g.t = f
g.x = f
g.p = d
m.t = f
m.x = f
m.p = d
n.t = f
n.x = f
n.p = d
c.w = e
c.p = e
c.q = g
h.r = f
h.x = d
e.w = c
e.p = c
e.q = j
assert d.x.r.q.p.x.r.w.p.w.txt == "c"