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.o: C = None
        self.r: C = None
        self.p: A = None
        self.txt = txt

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

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

m.r = f
m.s = d
e.o = a
e.r = d
e.p = f
a.t = d
a.o = f
a.q = m
j.o = d
j.r = d
j.p = f
c.o = d
c.r = d
c.p = m
f.r = m
f.s = a
d.t = a
d.o = f
d.q = f
assert m.r.r.r.s.o.s.o.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.o: C = None
        self.r: C = None
        self.p: A = None
        self.txt = txt

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

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

m.r = f
m.s = d
e.o = a
e.r = d
e.p = f
a.t = d
a.o = f
a.q = m
j.o = d
j.r = d
j.p = f
c.o = d
c.r = d
c.p = m
f.r = m
f.s = a
d.t = a
d.o = f
d.q = f
assert m.r.r.r.s.o.s.o.txt == "f"