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

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

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

i = A("i")
n = B("n")
d = C("d")
f = C("f")
j = B("j")

i.o = d
i.s = f
n.s = i
d.r = i
f.r = i
j.s = i
assert f.r.o.r.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.s: C = None
        self.txt = txt

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

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

i = A("i")
n = B("n")
d = C("d")
f = C("f")
j = B("j")

i.o = d
i.s = f
n.s = i
d.r = i
f.r = i
j.s = i
assert f.r.o.r.s.r.txt == "i"