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

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

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

k = A("k")
g = B("g")
f = C("f")
l = B("l")
n = A("n")

k.v = n
g.y = f
g.v = l
g.x = l
f.x = k
l.y = f
l.v = g
l.x = g
n.v = k
assert f.x.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

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

k = A("k")
g = B("g")
f = C("f")
l = B("l")
n = A("n")

k.v = n
g.y = f
g.v = l
g.x = l
f.x = k
l.y = f
l.v = g
l.x = g
n.v = k
assert f.x.v.v.txt == "k"