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

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

g = A("g")
j = B("j")
l = B("l")
f = A("f")

g.x = f
j.q = f
l.q = f
f.x = g
assert f.x.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.q: A = None
        self.txt = txt

g = A("g")
j = B("j")
l = B("l")
f = A("f")

g.x = f
j.q = f
l.q = f
f.x = g
assert f.x.x.x.x.txt == "f"