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

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

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

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

d.r = i
d.s = i
i.r = b
i.y = j
i.o = j
f.w = b
f.r = i
f.s = j
j.w = b
j.r = i
j.s = f
b.r = i
b.y = j
b.o = j
assert i.r.r.r.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.s: B = None
        self.txt = txt

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

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

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

d.r = i
d.s = i
i.r = b
i.y = j
i.o = j
f.w = b
f.r = i
f.s = j
j.w = b
j.r = i
j.s = f
b.r = i
b.y = j
b.o = j
assert i.r.r.r.o.txt == "j"