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

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

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

h = A("h")
d = B("d")
m = C("m")
k = A("k")
n = B("n")
l = A("l")

h.x = k
h.s = l
d.s = k
m.v = l
m.x = d
k.x = h
k.s = h
n.s = k
l.x = h
l.s = k
assert l.s.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.s: A = None
        self.txt = txt

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

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

h = A("h")
d = B("d")
m = C("m")
k = A("k")
n = B("n")
l = A("l")

h.x = k
h.s = l
d.s = k
m.v = l
m.x = d
k.x = h
k.s = h
n.s = k
l.x = h
l.s = k
assert l.s.x.x.txt == "k"