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

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

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

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

j = A("j")
e = B("e")
f = C("f")
b = D("b")
d = C("d")
l = D("l")
i = A("i")
g = B("g")
k = D("k")

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

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

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

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

j = A("j")
e = B("e")
f = C("f")
b = D("b")
d = C("d")
l = D("l")
i = A("i")
g = B("g")
k = D("k")

j.r = g
e.p = g
e.y = g
f.p = l
b.y = d
d.p = l
l.y = d
i.r = e
g.p = e
g.y = e
k.y = f
assert g.y.y.p.y.y.p.y.txt == "e"