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

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

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

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

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

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

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