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

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

k = A("k")
g = B("g")
n = B("n")
j = A("j")
e = A("e")
d = A("d")

k.u = n
k.y = d
g.y = n
g.p = n
n.y = g
n.p = g
j.u = g
j.y = k
e.u = n
e.y = k
d.u = g
d.y = j
assert e.u.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.y: A = None
        self.txt = txt

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

k = A("k")
g = B("g")
n = B("n")
j = A("j")
e = A("e")
d = A("d")

k.u = n
k.y = d
g.y = n
g.p = n
n.y = g
n.p = g
j.u = g
j.y = k
e.u = n
e.y = k
d.u = g
d.y = j
assert e.u.p.p.txt == "n"