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

class B:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: C = None
        self.txt = txt

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

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

f.s = k
f.p = m
f.r = b
h.q = m
h.t = b
l.v = k
l.z = k
k.s = f
k.p = j
k.r = l
m.q = h
m.t = b
j.q = m
j.t = l
b.v = k
b.z = k
assert f.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.p: B = None
        self.r: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: C = None
        self.txt = txt

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

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

f.s = k
f.p = m
f.r = b
h.q = m
h.t = b
l.v = k
l.z = k
k.s = f
k.p = j
k.r = l
m.q = h
m.t = b
j.q = m
j.t = l
b.v = k
b.z = k
assert f.s.s.s.txt == "k"