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

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

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

c = A("c")
d = B("d")
n = C("n")
j = A("j")
a = B("a")
l = B("l")
g = C("g")

c.y = l
c.r = j
d.r = l
n.p = a
j.y = d
j.r = c
a.r = d
l.r = a
g.p = l
assert j.r.r.r.y.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.r: A = None
        self.txt = txt

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

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

c = A("c")
d = B("d")
n = C("n")
j = A("j")
a = B("a")
l = B("l")
g = C("g")

c.y = l
c.r = j
d.r = l
n.p = a
j.y = d
j.r = c
a.r = d
l.r = a
g.p = l
assert j.r.r.r.y.r.r.txt == "d"