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

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

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

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

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

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

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