class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.y: 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.p: C = None
        self.txt = txt

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

j.r = d
j.y = e
e.y = j
m.p = c
f.y = j
l.r = e
l.y = e
k.p = m
d.y = l
a.p = k
c.p = k
assert l.r.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.y: 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.p: C = None
        self.txt = txt

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

j.r = d
j.y = e
e.y = j
m.p = c
f.y = j
l.r = e
l.y = e
k.p = m
d.y = l
a.p = k
c.p = k
assert l.r.y.y.txt == "e"