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

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

n = A("n")
c = B("c")
f = B("f")
j = A("j")
g = B("g")
d = B("d")
b = B("b")
l = A("l")

n.x = b
c.p = g
f.p = c
j.x = g
g.p = f
d.p = c
b.p = g
l.x = d
assert j.x.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

n = A("n")
c = B("c")
f = B("f")
j = A("j")
g = B("g")
d = B("d")
b = B("b")
l = A("l")

n.x = b
c.p = g
f.p = c
j.x = g
g.p = f
d.p = c
b.p = g
l.x = d
assert j.x.p.p.p.p.txt == "f"