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

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

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

i = A("i")
b = B("b")
e = C("e")
g = C("g")
d = B("d")
c = B("c")
j = C("j")
k = A("k")

i.y = c
i.r = c
i.s = d
b.y = i
e.v = b
g.v = b
d.y = i
c.y = k
j.v = b
k.y = b
k.r = c
k.s = d
assert i.s.y.s.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.r: B = None
        self.s: B = None
        self.txt = txt

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

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

i = A("i")
b = B("b")
e = C("e")
g = C("g")
d = B("d")
c = B("c")
j = C("j")
k = A("k")

i.y = c
i.r = c
i.s = d
b.y = i
e.v = b
g.v = b
d.y = i
c.y = k
j.v = b
k.y = b
k.r = c
k.s = d
assert i.s.y.s.txt == "d"