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

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

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

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

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

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

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

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

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