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

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

k = A("k")
g = B("g")
c = A("c")
n = B("n")
i = A("i")
f = B("f")

k.u = f
g.v = n
g.p = k
c.u = n
n.v = f
n.p = c
i.u = g
f.v = g
f.p = c
assert c.u.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

k = A("k")
g = B("g")
c = A("c")
n = B("n")
i = A("i")
f = B("f")

k.u = f
g.v = n
g.p = k
c.u = n
n.v = f
n.p = c
i.u = g
f.v = g
f.p = c
assert c.u.p.u.txt == "n"