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

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

c = A("c")
d = B("d")
h = B("h")
k = A("k")
f = B("f")
n = B("n")
e = A("e")

c.x = n
c.v = k
d.x = c
h.x = e
k.x = f
k.v = c
f.x = k
n.x = k
e.x = h
e.v = c
assert e.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.v: A = None
        self.txt = txt

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

c = A("c")
d = B("d")
h = B("h")
k = A("k")
f = B("f")
n = B("n")
e = A("e")

c.x = n
c.v = k
d.x = c
h.x = e
k.x = f
k.v = c
f.x = k
n.x = k
e.x = h
e.v = c
assert e.v.v.v.txt == "c"