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

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

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

d = A("d")
j = B("j")
c = C("c")
h = B("h")
k = C("k")

d.r = c
d.u = j
j.y = d
j.p = k
j.o = h
c.w = h
c.y = k
c.q = k
h.y = d
h.p = k
h.o = j
k.w = j
k.y = c
k.q = c
assert k.w.y.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.u: B = None
        self.txt = txt

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

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

d = A("d")
j = B("j")
c = C("c")
h = B("h")
k = C("k")

d.r = c
d.u = j
j.y = d
j.p = k
j.o = h
c.w = h
c.y = k
c.q = k
h.y = d
h.p = k
h.o = j
k.w = j
k.y = c
k.q = c
assert k.w.y.r.w.txt == "h"