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

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

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

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

k.x = m
k.r = m
k.y = g
m.s = k
g.x = n
g.y = d
g.p = d
n.x = m
n.r = m
n.y = g
d.x = n
d.y = g
d.p = g
assert d.p.x.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.r: B = None
        self.y: C = None
        self.txt = txt

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

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

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

k.x = m
k.r = m
k.y = g
m.s = k
g.x = n
g.y = d
g.p = d
n.x = m
n.r = m
n.y = g
d.x = n
d.y = g
d.p = g
assert d.p.x.y.p.txt == "d"