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

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

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

d = A("d")
h = B("h")
m = C("m")
c = A("c")
i = C("i")
j = B("j")
g = A("g")
f = C("f")
a = B("a")

d.r = j
d.p = i
h.r = i
h.o = d
h.s = m
m.q = h
m.x = g
m.v = c
c.r = j
c.p = i
i.q = h
i.x = c
i.v = d
j.r = i
j.o = d
j.s = m
g.r = j
g.p = i
f.q = j
f.x = g
f.v = d
a.r = i
a.o = c
a.s = f
assert c.r.s.x.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: C = None
        self.txt = txt

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

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

d = A("d")
h = B("h")
m = C("m")
c = A("c")
i = C("i")
j = B("j")
g = A("g")
f = C("f")
a = B("a")

d.r = j
d.p = i
h.r = i
h.o = d
h.s = m
m.q = h
m.x = g
m.v = c
c.r = j
c.p = i
i.q = h
i.x = c
i.v = d
j.r = i
j.o = d
j.s = m
g.r = j
g.p = i
f.q = j
f.x = g
f.v = d
a.r = i
a.o = c
a.s = f
assert c.r.s.x.r.s.txt == "m"