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

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

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

m = A("m")
f = B("f")
d = C("d")
g = A("g")
b = A("b")
n = B("n")
k = C("k")
c = C("c")
i = C("i")

m.p = n
m.o = f
m.z = i
f.r = n
d.q = b
d.o = c
d.x = k
g.p = n
g.o = n
g.z = d
b.p = n
b.o = f
b.z = k
n.r = f
k.q = g
k.o = i
k.x = c
c.q = b
c.o = i
c.x = d
i.q = b
i.o = k
i.x = d
assert g.o.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.o: B = None
        self.z: C = None
        self.txt = txt

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

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

m = A("m")
f = B("f")
d = C("d")
g = A("g")
b = A("b")
n = B("n")
k = C("k")
c = C("c")
i = C("i")

m.p = n
m.o = f
m.z = i
f.r = n
d.q = b
d.o = c
d.x = k
g.p = n
g.o = n
g.z = d
b.p = n
b.o = f
b.z = k
n.r = f
k.q = g
k.o = i
k.x = c
c.q = b
c.o = i
c.x = d
i.q = b
i.o = k
i.x = d
assert g.o.r.r.r.txt == "f"