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

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

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

g = A("g")
h = B("h")
j = C("j")
e = C("e")

g.r = h
h.r = g
h.s = g
h.u = j
j.s = e
j.r = h
j.q = g
e.s = j
e.r = h
e.q = g
assert j.q.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

g = A("g")
h = B("h")
j = C("j")
e = C("e")

g.r = h
h.r = g
h.s = g
h.u = j
j.s = e
j.r = h
j.q = g
e.s = j
e.r = h
e.q = g
assert j.q.r.r.r.txt == "h"