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

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

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

h = A("h")
i = B("i")
g = C("g")
f = C("f")
b = B("b")
j = C("j")
k = A("k")

h.r = k
i.y = k
g.u = j
g.q = h
f.u = j
f.q = k
b.y = h
j.u = g
j.q = k
k.r = h
assert f.q.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

h = A("h")
i = B("i")
g = C("g")
f = C("f")
b = B("b")
j = C("j")
k = A("k")

h.r = k
i.y = k
g.u = j
g.q = h
f.u = j
f.q = k
b.y = h
j.u = g
j.q = k
k.r = h
assert f.q.r.r.r.txt == "h"