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

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

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

n = A("n")
a = B("a")
g = C("g")
f = A("f")
j = C("j")

n.y = f
a.x = g
a.s = f
a.v = f
g.r = f
g.z = n
g.o = j
f.y = n
j.r = f
j.z = n
j.o = g
assert n.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

n = A("n")
a = B("a")
g = C("g")
f = A("f")
j = C("j")

n.y = f
a.x = g
a.s = f
a.v = f
g.r = f
g.z = n
g.o = j
f.y = n
j.r = f
j.z = n
j.o = g
assert n.y.y.y.y.y.txt == "f"