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

class B:
    def __init__(self, txt: str):
        self.w: D = None
        self.x: A = None
        self.txt = txt

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

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

g = A("g")
d = B("d")
c = C("c")
k = D("k")
a = B("a")
b = D("b")
l = D("l")
h = A("h")
m = C("m")
e = C("e")

g.y = a
g.p = b
g.w = h
d.w = l
d.x = g
c.x = b
k.p = b
k.r = h
a.w = b
a.x = g
b.p = l
b.r = g
l.p = b
l.r = h
h.y = a
h.p = b
h.w = g
m.x = k
e.x = k
assert b.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.p: D = None
        self.w: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: D = None
        self.x: A = None
        self.txt = txt

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

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

g = A("g")
d = B("d")
c = C("c")
k = D("k")
a = B("a")
b = D("b")
l = D("l")
h = A("h")
m = C("m")
e = C("e")

g.y = a
g.p = b
g.w = h
d.w = l
d.x = g
c.x = b
k.p = b
k.r = h
a.w = b
a.x = g
b.p = l
b.r = g
l.p = b
l.r = h
h.y = a
h.p = b
h.w = g
m.x = k
e.x = k
assert b.p.p.p.txt == "l"