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

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

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

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

k.r = j
k.s = f
b.v = j
b.r = k
h.o = f
h.v = a
h.r = b
f.o = a
f.v = h
f.r = b
j.r = k
j.s = h
a.o = h
a.v = h
a.r = b
assert j.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.s: C = None
        self.txt = txt

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

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

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

k.r = j
k.s = f
b.v = j
b.r = k
h.o = f
h.v = a
h.r = b
f.o = a
f.v = h
f.r = b
j.r = k
j.s = h
a.o = h
a.v = h
a.r = b
assert j.r.r.r.r.txt == "j"