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

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

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

m = A("m")
j = B("j")
e = C("e")
g = B("g")
n = C("n")
a = B("a")
k = C("k")
d = A("d")

m.r = d
j.r = n
e.y = d
e.w = m
g.r = n
n.y = d
n.w = m
a.r = e
k.y = m
k.w = m
d.r = m
assert e.w.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

m = A("m")
j = B("j")
e = C("e")
g = B("g")
n = C("n")
a = B("a")
k = C("k")
d = A("d")

m.r = d
j.r = n
e.y = d
e.w = m
g.r = n
n.y = d
n.w = m
a.r = e
k.y = m
k.w = m
d.r = m
assert e.w.r.r.r.r.txt == "m"