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

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

g = A("g")
d = B("d")
c = B("c")
k = A("k")
m = A("m")

g.y = m
g.p = m
d.v = g
c.v = k
k.y = m
k.p = g
m.y = k
m.p = g
assert k.p.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.p: A = None
        self.txt = txt

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

g = A("g")
d = B("d")
c = B("c")
k = A("k")
m = A("m")

g.y = m
g.p = m
d.v = g
c.v = k
k.y = m
k.p = g
m.y = k
m.p = g
assert k.p.y.y.y.y.txt == "k"