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

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

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

h = A("h")
n = B("n")
a = C("a")
j = A("j")
c = C("c")
f = B("f")
b = A("b")

h.p = n
h.y = c
h.o = a
n.x = f
n.z = f
n.p = j
a.p = f
a.z = c
a.r = b
j.p = n
j.y = a
j.o = a
c.p = n
c.z = a
c.r = b
f.x = n
f.z = n
f.p = b
b.p = n
b.y = c
b.o = a
assert a.r.p.x.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.y: C = None
        self.o: C = None
        self.txt = txt

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

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

h = A("h")
n = B("n")
a = C("a")
j = A("j")
c = C("c")
f = B("f")
b = A("b")

h.p = n
h.y = c
h.o = a
n.x = f
n.z = f
n.p = j
a.p = f
a.z = c
a.r = b
j.p = n
j.y = a
j.o = a
c.p = n
c.z = a
c.r = b
f.x = n
f.z = n
f.p = b
b.p = n
b.y = c
b.o = a
assert a.r.p.x.p.y.txt == "c"