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

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

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

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

h.r = n
c.r = f
c.z = f
c.q = f
d.s = f
k.s = f
n.r = h
n.z = h
n.q = f
m.s = h
f.r = n
g.s = f
e.s = f
j.s = f
assert m.s.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

h.r = n
c.r = f
c.z = f
c.q = f
d.s = f
k.s = f
n.r = h
n.z = h
n.q = f
m.s = h
f.r = n
g.s = f
e.s = f
j.s = f
assert m.s.r.r.txt == "h"