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

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

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

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

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

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

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

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

b.x = j
b.o = k
b.v = k
h.q = k
h.o = a
a.x = b
a.v = b
a.r = b
k.q = h
k.o = a
j.x = b
j.o = k
j.v = k
assert a.r.x.x.txt == "b"