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

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

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

d = A("d")
j = B("j")
e = C("e")
k = B("k")
f = A("f")
a = C("a")

d.t = f
d.q = f
d.r = a
j.s = a
e.y = k
e.o = a
k.s = e
f.t = d
f.q = d
f.r = a
a.y = k
a.o = e
assert d.r.y.s.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.q: A = None
        self.r: C = None
        self.txt = txt

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

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

d = A("d")
j = B("j")
e = C("e")
k = B("k")
f = A("f")
a = C("a")

d.t = f
d.q = f
d.r = a
j.s = a
e.y = k
e.o = a
k.s = e
f.t = d
f.q = d
f.r = a
a.y = k
a.o = e
assert d.r.y.s.txt == "e"