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

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

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

c = A("c")
m = B("m")
b = C("b")
k = A("k")
a = C("a")
j = B("j")
n = C("n")

c.v = k
m.s = k
m.p = j
b.q = a
k.v = c
a.q = n
j.s = c
j.p = m
n.q = a
assert c.v.v.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.s: A = None
        self.p: B = None
        self.txt = txt

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

c = A("c")
m = B("m")
b = C("b")
k = A("k")
a = C("a")
j = B("j")
n = C("n")

c.v = k
m.s = k
m.p = j
b.q = a
k.v = c
a.q = n
j.s = c
j.p = m
n.q = a
assert c.v.v.v.v.txt == "c"