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

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

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

n = A("n")
j = B("j")
b = C("b")
m = B("m")
k = A("k")
f = A("f")

n.y = f
n.r = j
j.u = f
j.z = f
j.x = m
b.o = n
m.u = k
m.z = k
m.x = j
k.y = f
k.r = m
f.y = k
f.r = j
assert k.r.x.x.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.r: B = None
        self.txt = txt

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

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

n = A("n")
j = B("j")
b = C("b")
m = B("m")
k = A("k")
f = A("f")

n.y = f
n.r = j
j.u = f
j.z = f
j.x = m
b.o = n
m.u = k
m.z = k
m.x = j
k.y = f
k.r = m
f.y = k
f.r = j
assert k.r.x.x.z.y.txt == "f"