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

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

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

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

c.r = m
c.q = m
c.y = a
j.y = m
j.p = c
m.v = c
b.y = f
b.p = c
f.v = k
k.r = m
k.q = m
k.y = b
a.y = f
a.p = k
assert k.y.y.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.q: C = None
        self.y: B = None
        self.txt = txt

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

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

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

c.r = m
c.q = m
c.y = a
j.y = m
j.p = c
m.v = c
b.y = f
b.p = c
f.v = k
k.r = m
k.q = m
k.y = b
a.y = f
a.p = k
assert k.y.y.v.r.txt == "m"